{"id":20614740,"url":"https://github.com/dashed/react-hashchange","last_synced_at":"2025-06-15T22:34:11.295Z","repository":{"id":57146901,"uuid":"104623831","full_name":"dashed/react-hashchange","owner":"dashed","description":"React component that notifies when browser's hash (i.e. `window.location.hash`) changes.","archived":false,"fork":false,"pushed_at":"2019-05-03T07:51:25.000Z","size":1783,"stargazers_count":5,"open_issues_count":5,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-16T17:06:33.340Z","etag":null,"topics":["change","hash","hashchange","react","react-hashchange","url"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dashed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-24T06:28:11.000Z","updated_at":"2021-04-24T22:36:32.000Z","dependencies_parsed_at":"2022-09-06T14:51:07.707Z","dependency_job_id":null,"html_url":"https://github.com/dashed/react-hashchange","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/dashed/react-hashchange","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Freact-hashchange","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Freact-hashchange/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Freact-hashchange/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Freact-hashchange/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dashed","download_url":"https://codeload.github.com/dashed/react-hashchange/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dashed%2Freact-hashchange/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":260060579,"owners_count":22953128,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["change","hash","hashchange","react","react-hashchange","url"],"created_at":"2024-11-16T11:13:29.884Z","updated_at":"2025-06-15T22:34:11.270Z","avatar_url":"https://github.com/dashed.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"react-hashchange [![Build Status](https://travis-ci.org/dashed/react-hashchange.svg)](https://travis-ci.org/dashed/react-hashchange) [![npm version](https://img.shields.io/npm/v/react-hashchange.svg?style=flat)](https://www.npmjs.com/package/react-hashchange)\n================\n\n[![Greenkeeper badge](https://badges.greenkeeper.io/dashed/react-hashchange.svg)](https://greenkeeper.io/)\n\n\u003e React component that notifies when browser's hash (i.e. `window.location.hash`) changes.\n\n## Install\n\n```sh\n$ yarn add react-hashchange\n# npm v5+\n$ npm install react-hashchange\n# before npm v5\n$ npm install --save react-hashchange\n```\n\n## Usage\n\n\n```js\n// 3rd-party imports\n\nimport ReactDOM from \"react-dom\";\nimport React, { Component } from \"react\";\n\nimport HashChange from \"react-hashchange\";\n\n// function as child component\n\nReactDOM.render(\n    \u003cHashChange onChange={({ hash }) =\u003e console.log({ hash })}\u003e\n        {({ hash }) =\u003e {\n            return \u003cdiv\u003e{`hash: ${hash}`}\u003c/div\u003e;\n        }}\n    \u003c/HashChange\u003e,\n    mountNode\n);\n\n// render prop\n\nconst render = ({ hash }) =\u003e {\n    return \u003cdiv\u003e{`hash: ${hash}`}\u003c/div\u003e;\n};\n\nReactDOM.render(\n    \u003cHashChange\n        onChange={({ hash }) =\u003e console.log({ hash })}\n        render={render}\n    /\u003e,\n    mountNode\n);\n```\n\n\n## Props\n\n### `render` (optional)\n\nThis is a `render` prop. To learn what that is, read: https://cdb.reacttraining.com/use-a-render-prop-50de598f11ce\n\nAn optional function that is called whenever the browser's hash (i.e. `window.location.hash`) changes.\n\nThe `render` function is invoked with an object argument: `({ hash })`.\n\n It's expected that `render` function returns a single React element.\nThis has same API semantics as [`React.Component.render()`](https://facebook.github.io/react/docs/react-component.html#render).\n\nIf `render` function is given, it has precedence over any given child component:\n\n```js\n\u003cHashChange\n    render={() =\u003e {\n        return (\n            \u003cdiv\u003e\"I take precedence over any function as child component.\"\u003c/div\u003e\n        );\n    }}\n\u003e\n    {() =\u003e {\n        return \u003cdiv\u003e\"I will not render.\"\u003c/div\u003e;\n    }}\n\u003c/HashChange\u003e\n```\n\n### Function as child component (optional)\n\nSame as `render` prop function (see above).\n\nIf `render` function is not given, then the child component will be invoked as a function.\n\nThe child component function is invoked with an object argument: `({ hash })`.\n\n```js\n\u003cHashChange\u003e\n    {({ hash }) =\u003e {\n        return \u003cdiv\u003e{`hash: ${hash}`}\u003c/div\u003e;\n    }}\n\u003c/HashChange\u003e\n````\n\n### `onChange` (optional)\n\nAn optional function that is called whenever the browser's hash (i.e. `window.location.hash`) changes.\n\nThe `onChange` function is invoked with an object argument: `({ hash })`.\n\n### `getLocationHash` (optional)\n\nAn optional function that returns the browser's hash. This function is called whenever `hashchange` event occurs.\n\nIf necessary, you may provide your own implementation of `getLocationHash` (e.g. handling browser nuances).\n\nBy default the implementation of `getLocationHash` is:\n\n```js\nconst getLocationHash = () =\u003e {\n    return window.location.hash;\n};\n```\n\nLicense\n=======\n\nMIT.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashed%2Freact-hashchange","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdashed%2Freact-hashchange","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdashed%2Freact-hashchange/lists"}