Redux-003-使用 react-redux

2019-10-28  本文已影响0人  空乱木

本文视频地址:https://www.qiuzhi99.com/movies/react-redux/150.html

参考链接
https://github.com/reactjs/react-redux
https://github.com/reactjs/react-redux/blob/master/docs/api.md

目录结构


image.png

代码
index.js

import {createStore} from 'redux';
import reducer from './reducers/counter';
import {increment,decrement} from './actions’;

import {Provider} from 'react-redux’;

const store = createStore(reducer);

ReactDOM.render(
<Provider store={store}>
<App />
</Provider>
, document.getElementById('root'));

App.js
//Store传值的实现
import {connect} from 'react-redux’;

const mapStateToProps = (state) => {
console.log(state);
return {
counter: state
};
};

export default connect(mapStateToProps)(App);

上一篇 下一篇

猜你喜欢

热点阅读