{"id":18789706,"url":"https://github.com/crewdevio/react-store","last_synced_at":"2025-04-13T14:06:00.708Z","repository":{"id":112325586,"uuid":"602193155","full_name":"crewdevio/react-store","owner":"crewdevio","description":"state management library for react based on svelte/store but adapted to the philosophy of react","archived":false,"fork":false,"pushed_at":"2023-06-07T18:58:48.000Z","size":6,"stargazers_count":12,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-11T01:40:44.274Z","etag":null,"topics":["nextjs","reactjs","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/crewdevio.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,"governance":null}},"created_at":"2023-02-15T17:36:05.000Z","updated_at":"2025-01-27T06:45:47.000Z","dependencies_parsed_at":"2023-05-09T11:01:05.022Z","dependency_job_id":null,"html_url":"https://github.com/crewdevio/react-store","commit_stats":{"total_commits":4,"total_committers":1,"mean_commits":4.0,"dds":0.0,"last_synced_commit":"9a91474906c6def91c878bf4dc8fb8088084e647"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crewdevio%2Freact-store","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crewdevio%2Freact-store/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crewdevio%2Freact-store/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/crewdevio%2Freact-store/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/crewdevio","download_url":"https://codeload.github.com/crewdevio/react-store/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248544696,"owners_count":21122001,"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":["nextjs","reactjs","state-management","typescript"],"created_at":"2024-11-07T21:08:22.013Z","updated_at":"2025-04-13T14:06:00.689Z","avatar_url":"https://github.com/crewdevio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## What is react-store-js?\n\nreact-store-js is a state management library for react based on [svelte/store](https://github.com/sveltejs/svelte/tree/master/src/runtime/store) but adapted to the philosophy of react.\n\n### Instalation\n\n```console\nnpm i react-store-js\n```\n\n### How to use:\n\nto use react-state-js is very simple, just initialize your global state and then import it in your component, to mutate/update the state you can use the different hooks\n\nexample: `counter.store.ts`\n\n```ts\nimport { createWritableStore } from \"react-store-js\";\n\nexport const counter = createWritableStore(0);\n```\n\non: `App.tsx`\n\n```tsx\nimport { useWritable } from \"react-store-js\";\nimport { counter } from \"./counter.store\";\n\nexport default function App() {\n  const $counter = useWritable(counter);\n\n  return (\n    \u003cdiv\u003e\n      \u003cbutton onClick={() =\u003e $counter.update(($counter) =\u003e $counter + 1)}\u003e\n        count is {$counter.value}\n      \u003c/button\u003e\n    \u003c/div\u003e\n  );\n}\n```\n\n\u003e **Note**: react-store-js is fully type-safe and typed, and generics can be used\n\n---\n\n### Methods:\n\n- `createWritableStore(initialState, StartStopNotifier?)`: creates a state that can be fined and read\n\n`example`:\n\n```ts\nexport const counter = createWritableStore(0);\n```\n\n---\n\n- `createReadableStore(initialState, StartStopNotifier?)`: creates a state that can only be read\n\n`example`:\n\n```ts\nexport const counter = createReadableStore(0);\n```\n\n---\n\n- `getStore(state)`: gets the state directly, works with read-only states as well as mutable states\n\n`example`:\n\n```ts\nexport const counter = createWritableStore(0);\n\nconst value = getStore(couter); // return 0\n```\n\n---\n\n### Hooks:\n\n- `useWritable(state)`: can be used to mutate, update, and read state\n\n`example`:\n\n```ts\n// initialize store\nconst counter = createWritableStore(0);\n\n// use store\nconst $counter = useWritable(counter);\n\n// mutate the state directly\n$counter.set(0);\n\n// update the current state\n$counter.update(($counter) =\u003e $counter + 1);\n\n// get actual state\n$counter.value;\n```\n\n---\n\n- `useReadable(state)`: used to read the read-only state\n\n`example`:\n\n```ts\n// initialize store\nexport const now = createReadableStore(Date.now());\n\nconst $now = useReadable(now);\n\n// get actual state\n$now.value;\n```\n\n---\n\n- `useDerived(state | state[], callback, initialState?)`: create a state whose value is based on the value of one or more other states\n\n`example`:\n\n```ts\n// initialize store\nconst counter = createWritableStore(0);\n\nconst $double = useDerived(counter, ($couter) =\u003e $counter * 2, 10);\n\n$double.value;\n```\n\n---\n\n- `useSubcriber(state, callback)`: used to listen for changes in state when the state changes\n\n`example`:\n\n```ts\nconst counter = createWritableStore(0);\n\nconst $counter = useWritable(counter);\n\n$counter.update(($counter) =\u003e $counter + 1);\n\nuseEffect(() =\u003e {\n  const unsubcribe = useSubcriber(counter, ($counter) =\u003e {\n    console.log($counter); // 1\n  });\n\n  // stop listening when component disconnects\n  return unsubcribe;\n}, []);\n```\n\n---\n\n### Advances examples:\n\n`createReadableStore` with inside mutation:\n\non: `time.store.ts`\n\n```ts\nexport const time = createReadableStore(0, (set) =\u003e {\n  const a = setInterval(() =\u003e set(Date.now()), 1000);\n\n  return () =\u003e clearInterval(a);\n});\n```\n\n`createWritableStore` with inside mutation:\n\non: `time.store.ts`\n\n```ts\nexport const time = createWritableStore(0, (set) =\u003e {\n  const a = setInterval(() =\u003e set(Date.now()), 1000);\n\n  return () =\u003e clearInterval(a);\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrewdevio%2Freact-store","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcrewdevio%2Freact-store","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcrewdevio%2Freact-store/lists"}