Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Zag | 2,202 | 29 | 16 hours ago | 100 | July 15, 2022 | 10 | mit | TypeScript | ||
Finite state machines for building accessible design systems and UI components. | ||||||||||
React Automata | 1,293 | 13 | 4 | 4 years ago | 27 | August 27, 2018 | 14 | mit | JavaScript | |
A state machine abstraction for React | ||||||||||
Little State Machine | 1,269 | 2 months ago | 8 | mit | TypeScript | |||||
📠 React custom hook for persist state management | ||||||||||
React | 437 | 41 | 16 | 4 months ago | 29 | July 27, 2021 | 43 | mit | TypeScript | |
🔼 UI-Router for React | ||||||||||
React Transition State | 247 | 4 | 4 days ago | 21 | September 07, 2022 | 9 | mit | JavaScript | ||
Zero dependency React transition state machine | ||||||||||
Use Machine | 222 | 2 years ago | 12 | February 21, 2020 | 4 | mit | TypeScript | |||
React Hook for using Statecharts powered by XState. use-machine. | ||||||||||
Xstate Examples | 123 | 2 days ago | 2 | TypeScript | ||||||
Practical examples of statechart-based solutions with xstate. | ||||||||||
Xoid | 101 | 2 days ago | 15 | February 20, 2022 | 2 | mit | TypeScript | |||
Framework-agnostic state management library designed for simplicity and scalability ⚛ | ||||||||||
React Machinery | 101 | 2 years ago | 6 | July 04, 2018 | 11 | mit | JavaScript | |||
🔥 React Machinery provides a simple to use, component based approach to state machines in react. | ||||||||||
Swiftelm | 91 | 4 years ago | 1 | mit | Swift | |||||
Reactive + Automaton + VTree in Swift, inspired by Elm. |
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.
<StateMachineProvider>
<App />
</StateMachineProvider>
createStore
Function to initialize the global store, invoked at your app root (where <StateMachineProvider />
lives).
function log(store) {
console.log(store);
return store;
}
createStore(
{
yourDetail: { firstName: '', lastName: '' } // it's an object of your state
},
{
name?: string; // rename the store
middleWares?: [ log ]; // function to invoke each action
storageType?: Storage; // session/local storage (default to session)
persist?: 'action' // onAction is default if not provided
// when 'none' is used then state is not persisted
// when 'action' is used then state is saved to the storage after store action is completed
// when 'beforeUnload' is used then state is saved to storage before page unloa
},
);
useStateMachine
This hook function will return action/actions and state of the app.
const { actions, state, getState } = useStateMachine<T>({
updateYourDetail,
});
Check out the Demo.
import React from 'react';
import {
StateMachineProvider,
createStore,
useStateMachine,
} from 'little-state-machine';
createStore({
yourDetail: { name: '' },
});
function updateName(state, payload) {
return {
...state,
yourDetail: {
...state.yourDetail,
...payload,
},
};
}
function YourComponent() {
const { actions, state } = useStateMachine({ updateName });
return (
<div onClick={() => actions.updateName({ name: 'bill' })}>
{state.yourDetail.name}
</div>
);
}
const App = () => (
<StateMachineProvider>
<YourComponent />
</StateMachineProvider>
);
You can create a global.d.ts
file to declare your GlobalState's type.
Checkout the example.
import 'little-state-machine';
declare module 'little-state-machine' {
interface GlobalState {
yourDetail: {
name: string;
};
}
}
Quick video tutorial on little state machine.
DevTool component to track your state change and action.
import { DevTool } from 'little-state-machine-devtools';
<StateMachineProvider>
<DevTool />
</StateMachineProvider>;
We also make BEEKAI. Build the next-generation forms with modern technology and best in class user experience and accessibility.