Let's provide the store to the root of our component tree:
- 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.
- Just before the App component is defined, create an instance of our store using our configureStore function:
const store = configureStore();
- 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.