Adding a store provider

Let's provide the store to the root of our component tree:

  1. In App.tsx, import the Provider component from React Redux and the configureStore function we created in the previous section. Add these import statements just after the React import statement:
import React, { lazy, Suspense } from 'react';
import { Provider } from 'react-redux';

import { configureStore } from './Store';

This is the first time we have referenced anything from React-Redux. Remember that this library helps React components interact with a Redux store.

  1. Just before the App component is defined, create an instance of our store using our configureStore function:
const store = configureStore();

  1. In the App component's JSX, wrap a Provider component around the BrowserRouter component by passing in our store instance:

return (
<Provider store={store}>
<BrowserRouter>
...
</BrowserRouter>
</Provider>
);

Components lower in the component tree can now connect to the store. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.164.241