Gathering detailed insights and metrics for react-sweet-state
Gathering detailed insights and metrics for react-sweet-state
Gathering detailed insights and metrics for react-sweet-state
Gathering detailed insights and metrics for react-sweet-state
npm install react-sweet-state
Typescript
Module System
Node Version
NPM Version
JavaScript (91.01%)
TypeScript (8.99%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
888 Stars
160 Commits
61 Forks
66 Watchers
12 Branches
84 Contributors
Updated on Jul 08, 2025
Latest Version
2.7.2
Package Id
react-sweet-state@2.7.2
Unpacked Size
127.45 kB
Size
25.66 kB
File Count
52
NPM Version
10.8.1
Node Version
20.16.0
Published on
Aug 24, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
3
38
The good parts of Redux and React Context in a flexible, scalable and easy to use state management solution
sweet-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.
Each 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.
Similar 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.
1npm i react-sweet-state 2# or 3yarn add react-sweet-state
1import { createStore, createHook } from 'react-sweet-state';
2
3const Store = createStore({
4 // value of the store on initialisation
5 initialState: {
6 count: 0,
7 },
8 // actions that trigger store mutation
9 actions: {
10 increment:
11 () =>
12 ({ setState, getState }) => {
13 // mutate state synchronously
14 setState({
15 count: getState().count + 1,
16 });
17 },
18 },
19 // optional, unique, mostly used for easy debugging
20 name: 'counter',
21});
22
23const useCounter = createHook(Store);
1// app.js 2import { useCounter } from './components/counter'; 3 4const CounterApp = () => { 5 const [state, actions] = useCounter(); 6 return ( 7 <div> 8 <h1>My counter</h1> 9 {state.count} 10 <button onClick={actions.increment}>+</button> 11 </div> 12 ); 13};
Check the docs website or the docs folder.
See sweet-state in action: run npm run start
and then go and check each folder:
http://localhost:8080/basic-flow/
http://localhost:8080/advanced-flow/
http://localhost:8080/advanced-scoped-flow/
To test your changes you can run the examples (with npm run start
).
Also, make sure you run npm run preversion
before creating you PR so you will double check that linting, types and tests are fine.
This library merges ideas from redux, react-redux, redux-thunk, react-copy-write, unstated, bey, react-apollo just to name a few. Moreover it has been the result of months of discussions with ferborva, pksjce, TimeRaider, dpisani, JedWatson, and other devs at Atlassian.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
Found 16/29 approved changesets -- score normalized to 5
Reason
branch protection is not maximal on development and all release branches
Details
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-14
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More