{"id":28484657,"url":"https://github.com/adiathasan/react-store-maker","last_synced_at":"2025-06-30T01:32:15.561Z","repository":{"id":53114394,"uuid":"428002431","full_name":"adiathasan/react-store-maker","owner":"adiathasan","description":"Utility function for creating stores for global state management with the context-API approach in react applications.","archived":false,"fork":false,"pushed_at":"2023-03-22T19:46:01.000Z","size":17,"stargazers_count":15,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-08T22:26:04.362Z","etag":null,"topics":["context-api","dispatch","hooks","react","reducer","typescript"],"latest_commit_sha":null,"homepage":"https://adiathasan.vercel.app","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/adiathasan.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,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-11-14T18:03:03.000Z","updated_at":"2022-10-31T05:34:51.000Z","dependencies_parsed_at":"2024-06-21T16:53:37.105Z","dependency_job_id":"f838da45-5365-4053-addc-a546ccb0acee","html_url":"https://github.com/adiathasan/react-store-maker","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/adiathasan/react-store-maker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adiathasan%2Freact-store-maker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adiathasan%2Freact-store-maker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adiathasan%2Freact-store-maker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adiathasan%2Freact-store-maker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adiathasan","download_url":"https://codeload.github.com/adiathasan/react-store-maker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adiathasan%2Freact-store-maker/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261430159,"owners_count":23157155,"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":["context-api","dispatch","hooks","react","reducer","typescript"],"created_at":"2025-06-07T22:35:27.467Z","updated_at":"2025-06-30T01:32:15.541Z","avatar_url":"https://github.com/adiathasan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# React Store maker\n\nCreate multiple stores with providers and get the store and dispatch hook for free with type safety!\n\n## How to use it\n\n**Install**\n\n```bash\nnpm install react-store-maker\nor\nyarn add react-store-maker\n```\n\n**Creating store with createStore function!**\n\n```typescript\n// ThemeConfig.ts\nimport { createStore } from 'react-store-maker';\n\nexport type Theme = 'light' | 'dark';\n\nconst init: Theme = 'light';\n\nexport type ThemeActions = { type: 'SET_DARK'; payload: 'dark' } | { type: 'SET_LIGHT'; payload: 'light' };\n\nconst reducer = (state: Theme = init, action: ThemeActions) =\u003e {\n\tswitch (action.type) {\n\t\tcase 'SET_LIGHT':\n\t\t\treturn action.payload;\n\t\tcase 'SET_DARK':\n\t\t\treturn action.payload;\n\t\tdefault:\n\t\t\treturn state;\n\t}\n};\n\nconst [ThemeProvider, useThemeStore, useThemeDispatch] = createStore(init, reducer);\n\nexport { ThemeProvider, useThemeStore, useThemeDispatch };\n\n// using with custom hook\nexport const useTheme = () =\u003e {\n\tconst theme = useThemeStore();\n\tconst dispatch = useThemeDispatch();\n\n\tconst toggleTheme = () =\u003e {\n\t\tconst newThemeAction: ThemeActions =\n\t\t\ttheme === 'light' ? { type: 'SET_DARK', payload: 'dark' } : { type: 'SET_LIGHT', payload: 'light' };\n\n\t\tdispatch(newThemeAction);\n\t};\n\n\treturn {\n\t\ttoggleTheme,\n\t\ttheme,\n\t};\n};\n```\n\n**Use it any where in your app after nesting at the top level**\n\n```tsx\n// App.tsx\nimport { ThemeProvider } from './ThemeConfig';\nimport { useTheme, useThemeStore } from './ThemeConfig';\n\nconst App = () =\u003e {\n\treturn (\n\t\t\u003cThemeProvider\u003e\n\t\t\t\u003cHeader /\u003e\n\t\t\t\u003cToggleThemeBtn /\u003e\n\t\t\u003c/ThemeProvider\u003e\n\t);\n};\n\nconst Header = () =\u003e {\n\tconst theme = useThemeStore();\n\n\treturn (\n\t\t\u003cdiv\u003e\n\t\t\t\u003ch1\u003eThe theme is - {theme}\u003c/h1\u003e\n\t\t\u003c/div\u003e\n\t);\n};\n\nexport const ToggleThemeBtn = () =\u003e {\n\tconst { toggleTheme } = useTheme();\n\n\treturn \u003cbutton onClick={toggleTheme}\u003eToggle theme\u003c/button\u003e;\n};\n```\n\n**Use multiple store providers for seperating logic**\n\n```tsx\nconst App = () =\u003e {\n\treturn (\n\t\t\u003cThemeProvider\u003e\n\t\t\t\u003cAuthProvider\u003e\n\t\t\t\t\u003cHeader /\u003e\n\t\t\t\t\u003cToggleThemeBtn /\u003e\n\t\t\t\u003c/AuthProvider\u003e\n\t\t\u003c/ThemeProvider\u003e\n\t);\n};\n\n// login.tsx\nconst Login = () =\u003e {\n\tconst { user } = useAuthStore();\n\n\tconst dispatch = useAuthDispatch();\n\n\treturn (\n\t\t\u003cdiv\u003e\n\t\t\t\u003ch1\u003ewelcome - {user}\u003c/h1\u003e\n\t\t\t\u003cbutton onClick={() =\u003e dispatch({ type: 'LOGOUT' })}\u003eLogout\u003c/button\u003e\n\t\t\u003c/div\u003e\n\t);\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadiathasan%2Freact-store-maker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadiathasan%2Freact-store-maker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadiathasan%2Freact-store-maker/lists"}