⚛️ Simple State Management from react to react powered by React Hook.
$ yarn add -E @evilfactory/global-state$ npm i @evilfactory/global-state - Zero configuration ✅.
- React hooks based API ✅.
- React Native supported ✅.
- Global State & shareable ✅.
- Redux Dev Tools supported 🙏.
as Wrapper of your React Application.
propsObjectprops.reducerprops.initialStateprops.children
reducerFunction | useReducerinitialStateObjectchildrenElement | createElement
Example Use of <StateProvider/>.
import React from 'react' import App from './you-app.js' import {StateProvider} from 'evilfactorylabs/global-state' const initialState = { todo: [] } function todoReducer(state, action) { switch (action.type) { case "ADD_TODO": return { ...state, todo: [...state.todo, action.todo] }; default: return state; } } ReactDOM.render( <StateProvider reducer={todoReducer} initialState={initialState}> <App/> </StateProvider> , document.getElementById('root'))newActionFunction? [optional]
import {useGlobalState} from '@evilfactorylabs/global-state' ... const createTodo = (state, action, todo) => { return action({ type: 'ADD_TODO', data: todo, }) } const [,addTodo] = useGlobalState(createTodo) addTodo({title: 'New Task'}) ...