{"id":16715140,"url":"https://github.com/dean177/use-url-state","last_synced_at":"2025-10-11T20:39:01.024Z","repository":{"id":40801329,"uuid":"98748561","full_name":"Dean177/use-url-state","owner":"Dean177","description":"Lift a React component's state into the url","archived":false,"fork":false,"pushed_at":"2022-12-10T01:32:37.000Z","size":9379,"stargazers_count":155,"open_issues_count":30,"forks_count":13,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-09-23T15:11:39.075Z","etag":null,"topics":["higher-order-component","hooks","javascript","react","render-props","state-management","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/Dean177.png","metadata":{"files":{"readme":"Readme.md","changelog":"CHANGELOG.md","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-07-29T17:28:15.000Z","updated_at":"2025-07-23T16:16:13.000Z","dependencies_parsed_at":"2023-01-26T01:32:14.296Z","dependency_job_id":null,"html_url":"https://github.com/Dean177/use-url-state","commit_stats":null,"previous_names":["dean177/with-url-state"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/Dean177/use-url-state","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dean177%2Fuse-url-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dean177%2Fuse-url-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dean177%2Fuse-url-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dean177%2Fuse-url-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Dean177","download_url":"https://codeload.github.com/Dean177/use-url-state/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Dean177%2Fuse-url-state/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279008623,"owners_count":26084480,"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","status":"online","status_checked_at":"2025-10-11T02:00:06.511Z","response_time":55,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["higher-order-component","hooks","javascript","react","render-props","state-management","typescript"],"created_at":"2024-10-12T21:08:28.547Z","updated_at":"2025-10-11T20:39:01.007Z","avatar_url":"https://github.com/Dean177.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# with-url-state\n\n[![CircleCI](https://circleci.com/gh/Dean177/with-url-state.svg?style=shield)](https://circleci.com/gh/Dean177/with-url-state)\n[![codecov](https://codecov.io/gh/Dean177/with-url-state/branch/master/graph/badge.svg)](https://codecov.io/gh/Dean177/with-url-state)\n[![Npm](https://badge.fury.io/js/with-url-state.svg)](https://www.npmjs.com/package/with-url-state)\n\nLifts the state out of a react component and into the url\n\n![color-example](./demo/color-example.gif)\n\n## Hooks\n\nThere is a [hook](https://reactjs.org/docs/hooks-intro.html) based api available on the [3.0.0](https://github.com/Dean177/with-url-state/tree/3.0.0) branch, published as a beta on [npm](https://www.npmjs.com/package/with-url-state/v/3.0.0-beta.0).\n\n## Installation\n\nTo install with npm use\n\n`npm install with-url-state --save`\n\nTo install with yarn use\n\n`yarn add with-url-state`\n\n## Usage\n\nCheck out the the [demo](https://dean177.github.io/with-url-state/) view the [code](https://github.com/Dean177/with-url-state/tree/master/demo) or play with it in [CodeSandbox](https://codesandbox.io/s/18x4l87yx7). \n\nUsing javascript\n\n```javascript\nimport React from 'react'\nimport { withUrlState } from 'with-url-state'\n\nconst enhance = withUrlState(props =\u003e ({ color: 'blue' }))\n\nexport const UrlForm = enhance(props =\u003e (\n  \u003cdiv className=\"UrlForm\"\u003e\n    \u003cdiv className=\"current-state\" style={{ backgroundColor: props.urlState.color }}\u003e\n      \u003cdiv\u003e{props.urlState.color}\u003c/div\u003e\n    \u003c/div\u003e\n    \u003cdiv className=\"color-buttons\"\u003e\n      \u003cbutton className=\"Red\" onClick={() =\u003e props.setUrlState({ color: 'red' })}\u003e\n        Red\n      \u003c/button\u003e\n      \u003cbutton className=\"Green\" onClick={() =\u003e props.setUrlState({ color: 'green' })}\u003e\n        Green\n      \u003c/button\u003e\n      \u003cbutton className=\"Blue\" onClick={() =\u003e props.setUrlState({ color: 'blue' })}\u003e\n        Blue\n      \u003c/button\u003e\n    \u003c/div\u003e\n  \u003c/div\u003e\n))\n```\n\nUsing typescript\n\n```typescript jsx\nimport React from 'react'\nimport { withUrlState, UrlStateProps } from 'with-url-state'\n\ntype OwnProps = {}\ntype UrlState = { color: string }\n\nconst enhance = withUrlState\u003cUrlState, OwnProps\u003e((prop: OwnProps) =\u003e ({ color: 'blue' }))\n\nexport const UrlForm = enhance((props: OwnProps \u0026 UrlStateProps\u003cUrlState\u003e) =\u003e (\n  \u003cdiv className=\"UrlForm\"\u003e\n    \u003cdiv className=\"current-state\" style={{ backgroundColor: props.urlState.color }}\u003e\n      \u003cdiv\u003e{props.urlState.color}\u003c/div\u003e\n    \u003c/div\u003e\n    \u003cdiv className=\"color-buttons\"\u003e\n      \u003cbutton className=\"Red\" onClick={() =\u003e props.setUrlState({ color: 'red' })}\u003e\n        Red\n      \u003c/button\u003e\n      \u003cbutton className=\"Green\" onClick={() =\u003e props.setUrlState({ color: 'green' })}\u003e\n        Green\n      \u003c/button\u003e\n      \u003cbutton className=\"Blue\" onClick={() =\u003e props.setUrlState({ color: 'blue' })}\u003e\n        Blue\n      \u003c/button\u003e\n    \u003c/div\u003e\n  \u003c/div\u003e\n))\n```\n\nUsing the render-prop component\n\n```typescript jsx\nimport React from 'react'\nimport { UrlState } from 'with-url-state'\n\ntype OwnProps = {}\ntype UrlState = { color: string }\n\nexport const UrlForm = (props: OwnProps) =\u003e (\n  \u003cUrlState\n    initialState={{ color: 'green' }}\n    render={({ setUrlState, urlState }) =\u003e (\n      \u003cdiv className=\"UrlForm\"\u003e\n        \u003cdiv className=\"current-state\" style={{ backgroundColor: urlState.color }}\u003e\n          \u003cdiv\u003e{urlState.color}\u003c/div\u003e\n        \u003c/div\u003e\n        \u003cdiv className=\"color-buttons\"\u003e\n          \u003cbutton className=\"Red\" onClick={() =\u003e setUrlState({ color: 'red' })}\u003e\n            Red\n          \u003c/button\u003e\n          \u003cbutton className=\"Green\" onClick={() =\u003e setUrlState({ color: 'green' })}\u003e\n            Green\n          \u003c/button\u003e\n          \u003cbutton className=\"Blue\" onClick={() =\u003e setUrlState({ color: 'blue' })}\u003e\n            Blue\n          \u003c/button\u003e\n        \u003c/div\u003e\n      \u003c/div\u003e\n    )}\n  /\u003e\n)\n```\n\n## Motivation\n\n`with-url-state` automates the query parameter manipulations, simplifying URL sharing for search results, querying data or tracking a visible portion of a map.\n\nThe api provided is:\n\n- based on [higer-order-components](https://reactjs.org/docs/higher-order-components.html) which makes it composable and testable\n- has a render-prop alternative for convenience\n- type-safe thanks to [Typescript](https://www.typescriptlang.org/)\n- very similar to [Reacts built in state](https://reactjs.org/docs/state-and-lifecycle.html) apis, so converting a component which already manages state is usually as simple as replacing `setState` with `setUrlState`!\n\n\n## Pollyfill\n\nFor use in IE11 you will need [https://github.com/kumarharsh/custom-event-polyfill](https://github.com/kumarharsh/custom-event-polyfill)\nand add `import 'custom-event-polyfill';` \n`if (typeof Event !== 'function') { window.Event = CustomEvent; }` to the upper scope of your application. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdean177%2Fuse-url-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdean177%2Fuse-url-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdean177%2Fuse-url-state/lists"}