1. import React from 'react';
    2. import ReactDOM from 'react-dom';
    3. import { Provider } from 'react-redux';
    4. import { BrowserRouter } from 'react-router-dom';
    5. import App from './App';
    6. import store from './redux/count_redux/store'
    7. ReactDOM.render(
    8. // React.StrictMode检查app和app包裹的组件是否合理
    9. <BrowserRouter>
    10. <Provider store={store}>
    11. <App />
    12. </Provider>
    13. </BrowserRouter>,
    14. document.getElementById('root')
    15. );

    在index.js中使用provide,provide上直接使用store,容器组件得到store,避免多个ui组件上调用store,不然就需要逐一的在ui组件标签上引入store,例如如下:

    1. import Login from './components/Login'
    2. import Register from "./components/Register"
    3. import store from './redux/store'
    4. function App() {
    5. return (
    6. <div>
    7. <Login store={store}/>
    8. <hr/>
    9. <Register store={store}/>
    10. </div>
    11. );
    12. }
    13. export default App;