react-redux连接给出未定义的道具

时间:2018-06-02 19:42:43

标签: reactjs redux react-redux state-management react-context

我正在使用react-redux进行状态管理并使用provider传递状态存储但我不知道为什么它在消费者部分中未定义 我的提供者组件

  render(){
    return (
        <Provider store = {store} >
            <ApolloProvider client = {client} >
                  <div className="row">
                        <SideBar />
                        <Center />
                        <RightSlidePanel />
                  </div>
          </ApolloProvider>
        </Provider>
    )
  }
}

RightSLidePanel组件

import { connect} from  'react-redux'
 class RightSlidePanel extends React.Component{
  constructor(){
    super();
    console.log("inside connect " + this.props);
  }
//render method here

}
const mapStateToProps = state => {
  return {
      loggedInUser : state.loggedInUser
    }

}
const mapDepatchToProps = dispatch =>{
  return {
    changeIsReduxWorking : answerTrueOrNot =>{
            dispatch({
              type : "CHANGE_REDUX_WORKING_STATUS",
              data : answerTrueOrNot
            });
    }
  }
}
export default connect(
  mapStateToProps,
  mapDepatchToProps
)(RightSlidePanel);

。 console.log的结果是undefined。 谢谢advacne

1 个答案:

答案 0 :(得分:0)

你没有将道具传递给超级,因为那里class ExchangeContainer extends Component { constructor(props) { super(props); this.state = { exchanges:[ { name:"binance", url:"https://bittrex.com" }, { name:"bittrex", url:"https://bittrex.com" } ], selectedExchange:null }; } render() { return ( <div className="ExchangeContainer list-group"> <ExchangeList exchanges={this.state.exchanges} selected={this.state.selectedExchange} onExchangeSelect={selectedExchange => this.setState({selectedExchange}) } /> <ExchangeDetail exchange={this.state.selectedExchange} /> </div> ); } } 未定义。

props