{"id":13450665,"url":"https://github.com/zcallan/use-browser-history","last_synced_at":"2025-07-11T04:37:44.404Z","repository":{"id":57387895,"uuid":"170865457","full_name":"zcallan/use-browser-history","owner":"zcallan","description":"A React hook to handle browser history events","archived":false,"fork":false,"pushed_at":"2019-02-15T16:10:43.000Z","size":3690,"stargazers_count":3,"open_issues_count":1,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-04-25T19:02:39.935Z","etag":null,"topics":["back","browser","history","hooks","modal","react","react-hooks","use","use-browser-history"],"latest_commit_sha":null,"homepage":"https://zcallan.github.io/use-browser-history/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zcallan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-02-15T13:00:18.000Z","updated_at":"2020-11-15T03:04:37.000Z","dependencies_parsed_at":"2022-09-06T08:51:41.976Z","dependency_job_id":null,"html_url":"https://github.com/zcallan/use-browser-history","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcallan%2Fuse-browser-history","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcallan%2Fuse-browser-history/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcallan%2Fuse-browser-history/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zcallan%2Fuse-browser-history/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zcallan","download_url":"https://codeload.github.com/zcallan/use-browser-history/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233446341,"owners_count":18677488,"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":["back","browser","history","hooks","modal","react","react-hooks","use","use-browser-history"],"created_at":"2024-07-31T07:00:37.106Z","updated_at":"2025-01-11T06:15:12.976Z","avatar_url":"https://github.com/zcallan.png","language":"JavaScript","funding_links":[],"categories":["Packages"],"sub_categories":[],"readme":"# use-browser-history\n\n\u003e A React hook to handle browser history events\n\n[![NPM](https://img.shields.io/npm/v/use-browser-history.svg)](https://www.npmjs.com/package/use-browser-history) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)\n\n![](example.gif)\n\nhttps://zcallan.github.io/use-browser-history/\n\n## Install\n\n```bash\nnpm install --save use-browser-history\n```\n\n## Usage\n\n```jsx\nimport React, { useState } from 'react'\n\nimport useBrowserHistory from 'use-browser-history'\n\nfunction Modal({ isOpen, onClose, onOpen }) {\n  const [handleBack] = useBrowserHistory( 'my-modal', isOpen, onClose, onOpen );\n\n  if ( !isOpen )\n    return null;\n\n  return (\n    \u003cdiv className=\"modal\"\u003e\n      \u003cdiv className=\"modal-backdrop\" onClick={handleBack} /\u003e\n\n      \u003cdiv className=\"modal-box\"\u003e\n        \u003cp\u003eHello!\u003c/p\u003e\n        \u003cbutton onClick={handleBack}\u003eClose modal\u003c/button\u003e\n      \u003c/div\u003e\n    \u003c/div\u003e\n  )\n}\n\nfunction App() {\n  const [isOpen, setIsOpen] = useState( false );\n\n  return (\n    \u003cdiv\u003e\n      \u003cbutton onClick={() =\u003e setIsOpen( true )}\u003eOpen modal\u003c/button\u003e\n\n      \u003cModal\n        isOpen={isOpen}\n        onClose={() =\u003e setIsOpen( false )}\n        onOpen={() =\u003e setIsOpen( true )}\n      /\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n## API\n\n```js\nconst [handleBack, handleForward] = useBrowserHistory( name, isActive, onBack, onForward );\n```\n\n|Key | Type | Description |\n|----|------|----------|\n|name|`string`|**(required)** The unique name to be used inside the browser history state. |\n|isActive|`bool`|**(required)** Whether or not the entry should exist in the browser history state. *For example, in the case of a modal, this should be set to `true` when the modal is open / visible, and `false` when it's closed.*|\n|onBack|`func`|A callback that is fired when the back button is pressed, or when the `handleBack` (first arg returned by `useBrowserHistory`) function is called and the browser history state has been cleaned up.|\n|onForward|`func`|Exactly like `onBack`, but for the forward button. You can use this to re-perform something if the user clicks back then forward (like in the example GIF above), to do something such as re-opening a modal.|\n\n## License\n\nMIT © [zcallan](https://github.com/zcallan)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzcallan%2Fuse-browser-history","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzcallan%2Fuse-browser-history","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzcallan%2Fuse-browser-history/lists"}