let data = [
{
name:"aaa",
gender:1,
birthday:"1999-07-23",
hobby:'篮球'
},
{
name:"bbb",
gender:1,
birthday:"1999-10-02",
hobby:'链球'
}
]
// Reducer
function counter(state = data, action) {
switch (action.type) {
default:
return state
}
}
const store = createStore(counter)
// Map Redux state to component props
function mapStateToProps(state) {
return {
value: state
}
}
// Map Redux actions to component props
function mapDispatchToProps(dispatch) {
return {
onAddClick: () => dispatch({type:"ADD"})
}
}
const App = connect(
mapStateToProps,
mapDispatchToProps
)(RootRouters)
ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById('root')
)
react-router的代码如下:
export default class RootRouters extends React.Component {
render(){
return (
<Router history = {browserHistory} >
<Route path ="/" component={Header} >
<IndexRoute component={Home} />
<Route path ='add' component={Add} />
<Route path ='edit' component={Edit} />
<Route path ='list' component={List} />
</Route>
</Router>
)
}
}
如果我的子组件比如Home要获取state状态该怎么获取,求指教
connect