Redux.
This React application uses a global state
management system that is based on
React-Redux . The Store configurations are located in the
src/redux folder. Each module's
actions are exported from
src/redux/moduleReducerName/actions.js
file. Each module's reducer is exported from
src/redux/moduleReducerName/index.js file.
The src/redux/store.js file is
handling global redux-store of the project.
Adding New Action.
In Redux, actions are used to trigger changes in the store. To create an action, you first need to create a function that returns an object with a type property. This type property specifies the type of action that will be dispatched. The object can also contain other properties that contain data that will be used by the reducer.
-
To do this, simply open up the actions file
src/redux/moduleReducerName/actions/index.js, or create a new one, and add a new action: - Once you have created your action, you need to bind it to a dispatch function. This dispatch function is provided by the Redux store and is used to dispatch actions to the reducer.
- Now, you need to add a new case for this action in the reducer.
- You can then use this new function in your component to trigger the action.