Utilise react hook to create a simple state management that stores data across application.
- Import dependencies.
import { StoreProvider, useStore } from './store/AppState';
- Initialize your application with
StoreProvider
. Wrap your content at the highest level.
const App = () => (
<StoreProvider initialState={initialState} reducers={[taskReducer]}>
// children
</StoreProvider>
);
- Access the states in any functional components.
const [state, dispatch] = useStore();