Gathering detailed insights and metrics for little-state-machine
Gathering detailed insights and metrics for little-state-machine
Gathering detailed insights and metrics for little-state-machine
Gathering detailed insights and metrics for little-state-machine
📠 React custom hook for persist state management
npm install little-state-machine
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
1,480 Stars
503 Commits
53 Forks
13 Watching
11 Branches
20 Contributors
Updated on 26 Nov 2024
Minified
Minified + Gzipped
TypeScript (94.17%)
JavaScript (5.83%)
Cumulative downloads
Total Downloads
Last day
-8.5%
57,307
Compared to previous day
Last week
-2.8%
305,553
Compared to previous week
Last month
8.3%
1,320,104
Compared to previous month
Last year
66.8%
13,588,555
Compared to previous year
1
State management made super simple
sessionStorage
or localStorage
)$ npm install little-state-machine
StateMachineProvider
This is a Provider Component to wrapper around your entire app in order to create context.
1<StateMachineProvider> 2 <App /> 3</StateMachineProvider>
createStore
Function to initialize the global store, invoked at your app root (where <StateMachineProvider />
lives).
1function log(store) {
2 console.log(store);
3 return store;
4}
5
6createStore(
7 {
8 yourDetail: { firstName: '', lastName: '' } // it's an object of your state
9 },
10 {
11 name?: string; // rename the store
12 middleWares?: [ log ]; // function to invoke each action
13 storageType?: Storage; // session/local storage (default to session)
14
15 persist?: 'action' // onAction is default if not provided
16 // when 'none' is used then state is not persisted
17 // when 'action' is used then state is saved to the storage after store action is completed
18 // when 'beforeUnload' is used then state is saved to storage before page unloa
19 },
20);
useStateMachine
This hook function will return action/actions and state of the app.
1const { actions, state, getState } = useStateMachine<T>({ 2 updateYourDetail, 3});
Check out the Demo.
1import React from 'react'; 2import { 3 StateMachineProvider, 4 createStore, 5 useStateMachine, 6} from 'little-state-machine'; 7 8createStore({ 9 yourDetail: { name: '' }, 10}); 11 12function updateName(state, payload) { 13 return { 14 ...state, 15 yourDetail: { 16 ...state.yourDetail, 17 ...payload, 18 }, 19 }; 20} 21 22function YourComponent() { 23 const { actions, state } = useStateMachine({ updateName }); 24 25 return ( 26 <div onClick={() => actions.updateName({ name: 'bill' })}> 27 {state.yourDetail.name} 28 </div> 29 ); 30} 31 32const App = () => ( 33 <StateMachineProvider> 34 <YourComponent /> 35 </StateMachineProvider> 36);
You can create a global.d.ts
file to declare your GlobalState's type.
Checkout the example.
1import 'little-state-machine'; 2 3declare module 'little-state-machine' { 4 interface GlobalState { 5 yourDetail: { 6 name: string; 7 }; 8 } 9}
Quick video tutorial on little state machine.
DevTool component to track your state change and action.
1import { DevTool } from 'little-state-machine-devtools'; 2 3<StateMachineProvider> 4 <DevTool /> 5</StateMachineProvider>;
We also make BEEKAI. Build the next-generation forms with modern technology and best in class user experience and accessibility.
Thanks go to these wonderful people:
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
packaging workflow detected
Details
Reason
Found 3/30 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
26 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-25
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