{"id":13429554,"url":"https://github.com/sin/react-immer-hooks","last_synced_at":"2025-03-16T03:31:50.767Z","repository":{"id":57333451,"uuid":"154918546","full_name":"sin/react-immer-hooks","owner":"sin","description":"Easy immutability in React Hooks with Immer.","archived":false,"fork":false,"pushed_at":"2018-10-27T03:02:00.000Z","size":21,"stargazers_count":45,"open_issues_count":1,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-17T22:49:37.199Z","etag":null,"topics":["copy-on-write","immer","react","react-hooks"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/react-immer-hooks","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/sin.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":"2018-10-27T02:58:47.000Z","updated_at":"2022-12-09T15:05:34.000Z","dependencies_parsed_at":"2022-08-24T20:42:31.419Z","dependency_job_id":null,"html_url":"https://github.com/sin/react-immer-hooks","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/sin%2Freact-immer-hooks","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sin%2Freact-immer-hooks/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sin%2Freact-immer-hooks/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sin%2Freact-immer-hooks/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sin","download_url":"https://codeload.github.com/sin/react-immer-hooks/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243822309,"owners_count":20353496,"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":["copy-on-write","immer","react","react-hooks"],"created_at":"2024-07-31T02:00:41.637Z","updated_at":"2025-03-16T03:31:50.480Z","avatar_url":"https://github.com/sin.png","language":"JavaScript","funding_links":[],"categories":["Packages","JavaScript"],"sub_categories":[],"readme":"# React Immer Hooks\n\n\u003e Easy immutability in [React Hooks](https://reactjs.org/docs/hooks-intro.html) with [Immer](https://github.com/mweststrate/immer).\n\n**Note:** _React Hooks are currently a [RFC proposal](https://github.com/reactjs/rfcs/pull/68) which may be subject to change. You'll need at least `react@16.7.0-alpha.0` to use this feature._\n\n## Installation\n\n`yarn add react-immer-hooks`\n\n## Usage\n\n##### useImmerState(initialState)\n\n```jsx\nimport { useImmerState } from 'react-immer-hooks'\n\nconst initialState = {\n  clicks: 0,\n  doubleClicks: 0\n}\n\nconst ClickCounters = () =\u003e {\n  const [ state, setState ] = useImmerState(initialState)\n\n  const onClick = () =\u003e setState(draft =\u003e { draft.clicks++ })\n  const onDoubleClick = () =\u003e setState(draft =\u003e { draft.doubleClicks++ })\n\n  return (\n    \u003c\u003e\n      \u003cbutton onClick={onClick} onDoubleClick={onDoubleClick}\u003e\n        Clics: {state.clicks}, Double clicks: {state.doubleClicks}\n      \u003c/button\u003e\n    \u003c/\u003e\n  )\n}\n```\n\n##### useImmerReducer(reducer, initialState)\n\n```jsx\nimport { useImmerReducer } from 'react-immer-hooks'\n\nconst initialState = {\n  count: 0\n}\n\nconst reducer = (draft, action) =\u003e {\n  if (action.type === 'INCREMENT') draft.count++\n  if (action.type === 'DECREMENT') draft.count--\n  if (action.type === 'ADD') draft.count += action.payload\n}\n\nconst Counter = () =\u003e {\n  const [ state, dispatch ] = useImmerReducer(reducer, initialState)\n\n  return (\n    \u003c\u003e\n      Count: {state.count}\n      \u003cbutton onClick={() =\u003e dispatch({ type: 'INCREMENT'})}\u003e\n        Increment\n      \u003c/button\u003e\n      \u003cbutton onClick={() =\u003e dispatch({ type: 'DECREMENT'})}\u003e\n        Decrement\n      \u003c/button\u003e\n      \u003cbutton onClick={() =\u003e dispatch({ type: 'ADD', payload: 5})}\u003e\n        Add 5\n      \u003c/button\u003e\n    \u003c/\u003e\n  )\n}\n```\n\n## License\n\nMIT License\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsin%2Freact-immer-hooks","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsin%2Freact-immer-hooks","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsin%2Freact-immer-hooks/lists"}