Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs React Redux“;无法读取属性';道具';“未定义”的定义;_Reactjs_Redux_React Props - Fatal编程技术网

Reactjs React Redux“;无法读取属性';道具';“未定义”的定义;

Reactjs React Redux“;无法读取属性';道具';“未定义”的定义;,reactjs,redux,react-props,Reactjs,Redux,React Props,我是个新手,我创造了一个简单的游戏。我现在决定重建它并开始使用Redux。我用 {React.cloneElement(this.props.children, this.props)} in `Main.js` 要将道具传递给第一个孩子World.js: Main.js (...) {React.cloneElement(this.props.children, this.props)} //props passed to World (...) export

我是个新手,我创造了一个简单的游戏。我现在决定重建它并开始使用Redux。我用

{React.cloneElement(this.props.children, this.props)} in `Main.js`  
要将道具传递给第一个孩子World.js:

 Main.js
    (...)
    {React.cloneElement(this.props.children, this.props)} //props passed to World
    (...)
 export default Main;
然后在World.js中,我将道具传递给接口组件:

World.js
   (...)
     <Interface
        {...this.props}
        /> 
   (...) 
export default World;

感谢所有感兴趣的人。

像这样添加construtor解决了这个问题

constructor(props) {
        super(props);

        this.getCurrentLocation = this.getCurrentLocation.bind(this);
        this.setCurrentLocation = this.props.setCurrentLocation.bind(this);
      }

你明白错误消息告诉你的是什么吗?不完全明白,我的想法是:我可以像return({this.props.locations.sampleLocation)一样在return中显示位置。它在组件中,但为什么不在这个组件中的函数中,因为“this”指当前组件?在使用Redux之前,它通常会工作。据我所知,它不会接收道具,因为您没有接收到任何构造函数。添加超级(道具)在你的构造函数中。@Przemek它告诉你的是,
这个
是未定义的。解决你的问题需要调查为什么会这样。我不认为这与redux有任何关系。这可能与你如何声明你的类和/或你的babel配置有关。我建议在C上发布一个小的repoode沙箱。
constructor(props) {
        super(props);

        this.getCurrentLocation = this.getCurrentLocation.bind(this);
        this.setCurrentLocation = this.props.setCurrentLocation.bind(this);
      }