合规国际互联网加速 OSASE为企业客户提供高速稳定SD-WAN国际加速解决方案。 广告
~~~ yarn add redux ~~~ ![](https://box.kancloud.cn/16122fe9628b53ae3a6f83ee8d6c268f_800x417.jpg) ## 1.在store文件下新建一个`index.js`的文件 管理数据 ~~~ import {createStore} from 'redux'; import reducer from './reducer'; const store = createStore(reducer); export default store; ~~~ ## 2.创建一个`reducer.js`取存储数据 ~~~ const defaultState={ inputValue:'', list:[] }; /* state指store中的数据 */ export default (state=defaultState,action)=>{ return state; } ~~~ ## 3.在App.js中导入store ~~~ import store from './store'; class App extends Component { constructor(props){ super(props); //getState()可以获取state中的数据 console.log(store.getState()) this.state = store.getState(); } } ~~~