创建store及reducer - 图1

index.js

import React from ‘react’; import ReactDOM from ‘react-dom’; import App from ‘./App’ import { createStore } from ‘redux’ import CounterReducer from ‘./Store/Reducer/Counter.reducer’ const store = createStore(CounterReducer) ReactDOM.render( <React.StrictMode> <App/> </React.StrictMode>, document.getElementById(‘root’) );

Counter.reducer.js

创建store及reducer - 图2

Counter.js

创建store及reducer - 图3

App.js

import React, { Component } from‘react’ import Counter from ‘./Components/Counter’ /** redux react-redux 需要安装这2个包 / class App extends Component { render() { return ( <div> <Counter/> </div> ) } } export default App