This template provides a minimal setup to get stater to work with React Hooks and Context API and create a scallable stores for your application.
The store is structured in a way that you can easily add new stores and keep them organized. The stores following the pattern called FLUX and are inspired by Redux. The stores are divided into this main parts:
- Initial State: The initial state is the state that will be used when the application starts, and also define the interface of the state must be used.
- Actions: The actions are a series of types that help to create the diferent action used to mutate the states.
- Reducer: Use the actions to mutate the state. Each action have a specific function that will be executed when the action is dispatched.
- Context: The context is the place where the state is stored and the actions are dispatched.
- Provider: The provider is the component that will wrap the application and provide the context to the application.
- Hooks: The hooks are used to access the state and the actions from the context.
-
Create a project from a template using a tool like degit or simple clone the repository.
Clone using degit:
npx degit gsi-chao/react-hooks-store-starter test
Clone usign git
git clone https://github.com/gsi-chao/react-hooks-store-starter.git
-
Create a new store using the template provided in the
src/stores
folder. -
Add the Provider to the top of your application, module or component.
-
Use the useStore hook to access the state and the actions.
-
Use the states and dispatch the actions to mutate the state.
- Clone the repository.
- Install the dependencies using
npm install
. - Run the application using
npm run dev
. - Open the browser in
http://localhost:5173
.