{"id":13468367,"url":"https://github.com/atlassian/react-sweet-state","last_synced_at":"2025-05-14T23:06:30.538Z","repository":{"id":37484375,"uuid":"182970917","full_name":"atlassian/react-sweet-state","owner":"atlassian","description":"Shared state management solution for React","archived":false,"fork":false,"pushed_at":"2024-08-24T04:41:23.000Z","size":2706,"stargazers_count":885,"open_issues_count":29,"forks_count":57,"subscribers_count":67,"default_branch":"master","last_synced_at":"2025-04-15T00:44:32.048Z","etag":null,"topics":["context-api","reactjs","redux","state-management"],"latest_commit_sha":null,"homepage":"https://atlassian.github.io/react-sweet-state/","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/atlassian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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":"2019-04-23T08:35:05.000Z","updated_at":"2025-04-14T17:50:36.000Z","dependencies_parsed_at":"2023-11-20T00:26:20.995Z","dependency_job_id":"283fcd59-ff9c-41ac-88cd-bec1f3c5bd8d","html_url":"https://github.com/atlassian/react-sweet-state","commit_stats":{"total_commits":156,"total_committers":32,"mean_commits":4.875,"dds":"0.41666666666666663","last_synced_commit":"0384e2803a60a59287b45a2ef3d3e7f6bfccce61"},"previous_names":[],"tags_count":36,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Freact-sweet-state","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Freact-sweet-state/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Freact-sweet-state/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atlassian%2Freact-sweet-state/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atlassian","download_url":"https://codeload.github.com/atlassian/react-sweet-state/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254243360,"owners_count":22038046,"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","reactjs","redux","state-management"],"created_at":"2024-07-31T15:01:09.600Z","updated_at":"2025-05-14T23:06:25.510Z","avatar_url":"https://github.com/atlassian.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","react","List","🌐 Web Development - Frontend"],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://user-images.githubusercontent.com/84136/59560300-2fca8e80-9053-11e9-8f90-76d9ef281ca6.png\" alt=\"react-sweet-state logo\" height=\"150\" /\u003e\n\u003c/p\u003e\n\u003ch1 align=\"center\"\u003ereact-sweet-state\u003c/h1\u003e\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/react-sweet-state\"\u003e\u003cimg src=\"https://img.shields.io/npm/v/react-sweet-state.svg\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://bundlephobia.com/result?p=react-sweet-state\"\u003e\u003cimg src=\"https://img.shields.io/bundlephobia/minzip/react-sweet-state.svg\" /\u003e\u003c/a\u003e\n  \u003ca href=\"LICENSE\"\u003e\u003cimg src=\"https://img.shields.io/badge/license-MIT-blue.svg\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://codecov.io/gh/atlassian/react-sweet-state\"\u003e\u003cimg src=\"https://codecov.io/gh/atlassian/react-sweet-state/branch/master/graph/badge.svg\" /\u003e\u003c/a\u003e\n  \u003ca href=\"CONTRIBUTING.md\"\u003e\u003cimg src=\"https://img.shields.io/badge/PRs-welcome-brightgreen.svg\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\nThe good parts of Redux and React Context in a flexible, scalable and easy to use state management solution\n\n## Philosophy\n\nsweet-state is heavily inspired by Redux mixed with Context API concepts. It has render-prop components or hooks, connected to Store instances (defined as actions and initial state), receiving the Store state (or part of it) and the actions as a result.\n\nEach `Hook`, or `Subscriber`, is responsible to get the instantiated Store (creating a new one with `initialState` if necessary), allowing sharing state across your project extremely easy.\n\nSimilar to Redux thunks, actions receive a set of arguments to get and mutate the state. The default `setState` implementation is similar to React `setState`, accepting an object that will be shallow merged with the current state. However, you are free to replace the built-in `setState` logic with a custom mutator implementation, like `immer` for instance.\n\n## Basic usage\n\n```sh\nnpm i react-sweet-state\n# or\nyarn add react-sweet-state\n```\n\n#### Creating and consuming stores\n\n```js\nimport { createStore, createHook } from 'react-sweet-state';\n\nconst Store = createStore({\n  // value of the store on initialisation\n  initialState: {\n    count: 0,\n  },\n  // actions that trigger store mutation\n  actions: {\n    increment:\n      () =\u003e\n      ({ setState, getState }) =\u003e {\n        // mutate state synchronously\n        setState({\n          count: getState().count + 1,\n        });\n      },\n  },\n  // optional, unique, mostly used for easy debugging\n  name: 'counter',\n});\n\nconst useCounter = createHook(Store);\n```\n\n```js\n// app.js\nimport { useCounter } from './components/counter';\n\nconst CounterApp = () =\u003e {\n  const [state, actions] = useCounter();\n  return (\n    \u003cdiv\u003e\n      \u003ch1\u003eMy counter\u003c/h1\u003e\n      {state.count}\n      \u003cbutton onClick={actions.increment}\u003e+\u003c/button\u003e\n    \u003c/div\u003e\n  );\n};\n```\n\n## Documentation\n\nCheck the [docs website](https://atlassian.github.io/react-sweet-state/) or the [docs folder](docs/README.md).\n\n## Examples\n\nSee sweet-state in action: run `npm run start` and then go and check each folder:\n\n- Basic example with Flow typing `http://localhost:8080/basic-flow/`\n- Advanced async example with Flow typing `http://localhost:8080/advanced-flow/`\n- Advanced scoped example with Flow typing `http://localhost:8080/advanced-scoped-flow/`\n\n## Contributing\n\nTo test your changes you can run the examples (with `npm run start`).\nAlso, make sure you run `npm run preversion` before creating you PR so you will double check that linting, types and tests are fine.\n\n## Thanks\n\nThis library merges ideas from redux, react-redux, redux-thunk, react-copy-write, unstated, bey, react-apollo just to name a few.\nMoreover it has been the result of months of discussions with [ferborva](https://github.com/ferborva), [pksjce](https://github.com/pksjce), [TimeRaider](https://github.com/TimeRaider), [dpisani](https://github.com/dpisani), [JedWatson](https://github.com/JedWatson), and other devs at [Atlassian](https://github.com/atlassian).\n\n\u003cbr/\u003e\n\n[![With ❤️ from Atlassian](https://raw.githubusercontent.com/atlassian-internal/oss-assets/master/banner-cheers-light.png)](https://www.atlassian.com)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatlassian%2Freact-sweet-state","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatlassian%2Freact-sweet-state","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatlassian%2Freact-sweet-state/lists"}