Store
A store is a place where we store all the data, it is a single source, centralized store from where any component can update and get state.
- createStore(): To initialize store, usecreateStore() method which takes object of reducers.
- dispatch(action): To update the state, we need to dispatch an action which then triggers the reducer function to update the state.
- getState(): To get the state from the store, getState() method is used. It returns the current state of the store.
Syntax of Store:
// createStore()
const store = createStore(INITIAL_STATE);
// dispatch(action)
store.dispatch(actionCreator(data));
// getState()
const current_state = store.getState();
What are the 3 core concepts of React Redux ?
Redux is a widely-used state management library that helps in managing the state in our projects. However, it comes with its own terminologies and jargon that can be confusing for beginners. Essentially, Redux comprises of three core concepts: actions, reducers, and store.
In this article, we will cover these concepts in detail and provide an example of how they can be used. By understanding these core concepts, you will be able to work with Redux more efficiently and effectively.