以下纯属个人的学习方式
// 一、 index.js 主要代码
import { Provider } from 'react-redux'
import { createStore} from 'redux'
import reducer from './reducers' // 相当于vue 的store
const store = createStore(reducer)
render(
//监听变化并 注入全局store
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
)
// 二、在需要的的组件使用;
import { connect } from 'react-redux'
import { checkout } from '../actions'
//LstContainer 组件
<LstContainer list={list}
onCheckoutClicked={() => checkout(list)} />
const mapStateToProps = (state) => ({
list:state.list ,
})
export default connect(
mapStateToProps, // 相当于 vue 的 mapGetters
{ checkout } // 相当于 vue 的 mapActions
)(LstContainer )
// 三、store对比
import { combineReducers } from 'redux' // modules
import {a} from './a' ; //moduleA
import {b} from './b' ; /