Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
243 views
in Technique[技术] by (71.8m points)

react-redux遇到的问题

    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状态该怎么获取,求指教

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

connect


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...