Get Started with Redux in React Application

npm install --save react-redux @reduxjs/toolkit

Create a file src/store/index.js and add following code in it:

import { configureStore } from '@reduxjs/toolkit';
import { combineReducers } from 'redux';
const reducer = combineReducers({
  // here we will be adding reducers
})
const store = configureStore({
  reducer,
})
export default store;

To link our app with the redux store update the main app file as follows:

...
...
import { Provider } from 'react-redux';
import store from './store';

ReactDOM.render(
  <Provider store={store}>
      <App />
    </Provider>
,
  document.getElementById('root')
);

Leave a Comment