1、通过createStore创建好store
import { createStore } from 'redux'
import reducer from './reducer'
const store = createStore(reducer);
export default store
2、在需要使用state的地方调用 store.getState()获取store中存储的状态
constructor(props) {
super(props);
this.state = store.getState(); // 通过getState方法获store中的状态
this.hotChangeState = this.hotChangeState.bind(this);
store.subscribe(this.hotChangeState);
}
3、实时更新state的内容 store.subscribe(this.hotChangeState)
hotChangeState() {
this.setState(store.getState())
}