{"id":36800737,"url":"https://github.com/yezyilomo/simple-react-state","last_synced_at":"2026-01-12T13:33:58.596Z","repository":{"id":35778810,"uuid":"219213877","full_name":"yezyilomo/simple-react-state","owner":"yezyilomo","description":"React state manager based on react hooks and react-redux.","archived":false,"fork":false,"pushed_at":"2023-01-05T03:55:33.000Z","size":922,"stargazers_count":5,"open_issues_count":12,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-05-11T22:44:40.142Z","etag":null,"topics":["react-hooks","react-hooks-store","react-redux","react-starter-kit","react-state-management","react-store","redux","state-management"],"latest_commit_sha":null,"homepage":null,"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/yezyilomo.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":"2019-11-02T21:05:33.000Z","updated_at":"2020-05-11T14:00:02.000Z","dependencies_parsed_at":"2023-01-16T06:18:42.636Z","dependency_job_id":null,"html_url":"https://github.com/yezyilomo/simple-react-state","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/yezyilomo/simple-react-state","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yezyilomo%2Fsimple-react-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yezyilomo%2Fsimple-react-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yezyilomo%2Fsimple-react-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yezyilomo%2Fsimple-react-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yezyilomo","download_url":"https://codeload.github.com/yezyilomo/simple-react-state/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yezyilomo%2Fsimple-react-state/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28339201,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-12T12:22:26.515Z","status":"ssl_error","status_checked_at":"2026-01-12T12:22:10.856Z","response_time":98,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["react-hooks","react-hooks-store","react-redux","react-starter-kit","react-state-management","react-store","redux","state-management"],"created_at":"2026-01-12T13:33:58.420Z","updated_at":"2026-01-12T13:33:58.536Z","avatar_url":"https://github.com/yezyilomo.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-react-state\nA simple react state manager based on react hooks and react-redux which makes working with both local and global states completely painless it also works pretty well with nested states.\n\n## Installing\n```\nyarn add https://github.com/yezyilomo/simple-react-state\n```\n\n## Getting Started\n### Using local state\n```js\nimport React from 'react';\nimport { useLocalState } from 'simple-react-state';\n\n\nfunction UserInfo(props){\n    const [user, updateUser] = useLocalState({email: \"\"})\n\n    let setUserEmail = (e) =\u003e {\n        updateUser({\n            field: 'email',\n            value: e.target.value\n        });\n    }\n\n    return (\n        \u003cdiv\u003e\n            User Email: {user.email}\n            \u003cbr/\u003e\n            \u003cinput type=\"text\" name=\"email\" value={user.email} onChange={setUserEmail} /\u003e\n        \u003c/div\u003e\n    );\n}\n\nconst App = \u003cUserInfo/\u003e\nReactDOM.render(App, document.querySelector(\"#root\"));\n```\n\n### Using global state\n```js\nimport React from 'react';\nimport {\n    Provider, configureStore, useGlobalState\n} from 'simple-react-state';\n\n\nlet initialState = {\n    user: {\n        email: \"\"\n    }\n};\n\nlet store = configureStore({\n    initialState: initialState\n});\n\nfunction UserInfo(props){\n    const [user, updateUser] = useGlobalState('user');\n\n    let setUserEmail = (e) =\u003e {\n        updateUser({\n            field: 'email',\n            value: e.target.value\n        });\n    }\n\n    return (\n        \u003cdiv\u003e\n            User Email: {user.email}\n            \u003cbr/\u003e\n            \u003cinput type=\"text\" name=\"email\" value={user.email} onChange={setUserEmail} /\u003e\n        \u003c/div\u003e\n    );\n}\n\nconst App = \u003cProvider store={store}\u003e\u003cUserInfo/\u003e\u003c/Provider\u003e\nReactDOM.render(App, document.querySelector(\"#root\"));\n```\n\n## API\n### `useLocalState` hook\n`useLocalState` works just like `useState` hook, it accepts initial state as an argument except it returns an array of local state and `updateState` function(not `setState` like in `useState` hook).\n\n```js\nlet user = {\n    name: 'Yezy',\n    age: 24,\n    account: {\n        id: '23334',\n        balance: 433.3\n    }\n}\n\n[user, updateUser] = useLocalState(user)\n```\n\n### `useGlobalState` hook\n`useGlobalState` works just like `useState` hook too but it accepts a selection string and returns an array of three items which are `state`, `updateState` and `dispatch`, in most cases you will be using the first two items(state and updateState), the last item(dispatch) is for dispatching custom actions if you will have any. For example if you have a store with data like\n```js\n{\n    user: {\n        name: 'Yezy',\n        age: 24,\n        account: {\n            id: '23334',\n            balance: 433.3\n        }\n    }\n}\n```\n\nyou can use `useGlobalState` hook to select a deeply nested state like\n```js\n[age, updateAge, dispatch] = useGlobalState('user.age')\n```\n\n```js\n[account, updateAccount, dispatch] = useGlobalState('user.account')\n```\n\n```js\n[balance, updateBalance, dispatch] = useGlobalState('user.account.balance')\n```\n\n**Note:** If you pass nothing to `useGlobalState` the whole store is selected.\n\n### `updateState`\n`updateState` function works the same on both `useGlobalState` and `useLocalState` hooks, it dispatches an action to perform update on state, an action dispatched should have the following format \n\n```js\nupdateState({\n    type: 'update type',\n    field: 'your field',\n    value: 'your value'\n})\n```\n\nwhere type can be `ASSIGN`, `PUSH`, `POP`, `REMOVE` or `FILTER`, `ASSIGN` is for assigning a value to a field, `PUSH`, `POP`, `REMOVE` and `FILTER` are for arrays(correspond with array methods).\n\n\n`ASSIGN` is the default action type, so if you haven't passed the type of your action that one will be used, therefore with this in mind\n\n```js\nupdateUser({\n    field: 'email',\n    value: 'user@email.com'\n})\n```\n\nis the same as\n```js\nupdateUser({\n    type: 'ASSIGN',\n    field: 'email',\n    value: 'user@email.com'\n})\n```\n\n### `setState`\n**simple-react-state** allows you to set global state with `setState` method from store object, `setState` works just like `updateState` in fact they are both using the same reducer(`updateReducer`), so all action types supported by `updateState` are also supported by `setState` too. Here is how to use it\n\n```js\nstore.setState({\n    type: 'ASSIGN',\n    field: 'your field',\n    value: 'your value'\n});\n```\n\n**Note:** This should be used outside of your component.\n\nWith this in mind the first example above could be re-written to \n\n```js\nimport React from 'react';\nimport {\n    Provider, configureStore,\n    useGlobalState, useLocalState\n} from 'simple-react-state';\n\n\nlet store = configureStore({});\n\nstore.setState(\n    type: 'ASSIGN',\n    field: 'user',\n    value: {email: ''}\n)\n\nfunction UserInfo(props){\n    const [user, updateUser] = useGlobalState('user');\n\n    let setUserEmail = (e) =\u003e {\n        updateUser({\n            type: 'ASSIGN',\n            field: 'email',\n            value: e.target.value\n        });\n    }\n\n    return (\n        \u003cdiv\u003e\n            User Email: {user.email}\n            \u003cbr/\u003e\n            \u003cinput type=\"text\" name=\"email\" value={user.email} onChange={setUserEmail} /\u003e\n        \u003c/div\u003e\n    );\n}\n\nconst App = \u003cProvider store={store}\u003e\u003cUserInfo/\u003e\u003c/Provider\u003e\nReactDOM.render(App, document.querySelector(\"#root\"));\n```\n\nPretty cool, right?","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyezyilomo%2Fsimple-react-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyezyilomo%2Fsimple-react-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyezyilomo%2Fsimple-react-state/lists"}