{"id":17677421,"url":"https://github.com/unadlib/use-immutable","last_synced_at":"2025-05-12T21:28:47.078Z","repository":{"id":57388132,"uuid":"304339444","full_name":"unadlib/use-immutable","owner":"unadlib","description":"A hook for creating the immutable state with mutations on React","archived":false,"fork":false,"pushed_at":"2020-10-22T18:01:45.000Z","size":245,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-22T15:56:40.899Z","etag":null,"topics":[],"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/unadlib.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":"2020-10-15T13:44:03.000Z","updated_at":"2023-03-08T16:54:02.000Z","dependencies_parsed_at":"2022-09-14T16:10:33.686Z","dependency_job_id":null,"html_url":"https://github.com/unadlib/use-immutable","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unadlib%2Fuse-immutable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unadlib%2Fuse-immutable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unadlib%2Fuse-immutable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/unadlib%2Fuse-immutable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/unadlib","download_url":"https://codeload.github.com/unadlib/use-immutable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253824708,"owners_count":21970062,"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":[],"created_at":"2024-10-24T07:28:39.634Z","updated_at":"2025-05-12T21:28:47.035Z","avatar_url":"https://github.com/unadlib.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# use-immutable\n\n![Node CI](https://github.com/unadlib/use-immutable/workflows/Node%20CI/badge.svg)\n[![npm version](https://badge.fury.io/js/use-immutable.svg)](http://badge.fury.io/js/use-immutable)\n\nA hook for creating the immutable state with mutations on React, it's based on [immer](https://github.com/immerjs/immer). \n\n## Features\n\n- Update state by mutating\n- Snapshot\n- Time traveling\n\n## Usage\n\n- Installation\n\n```sh\nyarn add use-immutable\n```\n\n- Example: [Demo](https://stackblitz.com/edit/use-immutable)\n\n```js\nimport React from 'react';\nimport { useImmutable } from 'use-immutable';\n\nconst TodoList = () =\u003e {\n  const todo = useImmutable({\n    text: '',\n    list: [],\n  });\n  const updateText = (e) =\u003e\n    todo.set(() =\u003e {\n      todo.state.text = e.target.value;\n    });\n  const addTodo = () =\u003e\n    todo.set(() =\u003e {\n      todo.state.list.push(todo.state.text);\n      todo.state.text = '';\n    });\n  return (\n    \u003cdiv\u003e\n      \u003cinput value={todo.state.text} onChange={updateText} /\u003e\n      \u003cbutton onClick={addTodo}\u003eAdd\u003c/button\u003e\n      \u003cul\u003e\n        {todo.state.list.map((item, index) =\u003e (\n          \u003cli key={index}\u003e{item}\u003c/li\u003e\n        ))}\n      \u003c/ul\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n## APIs\n\n### instance.state\n\nGet the current component status.\n\n### instance.snapshot()\n\nTake a snapshot of the current state\n\n### instance.pop()\n\nUpdate the state from the snapshot\n\n### instance.clear()\n\nClear the snapshot\n\n### instance.length\n\nGet the snapshot length\n\n### instance.index\n\nIndex of the current state in the snapshot\n\n### instance.set()\n\nSet a new state value\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funadlib%2Fuse-immutable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funadlib%2Fuse-immutable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funadlib%2Fuse-immutable/lists"}