简体   繁体   English

TypeError:无法读取未定义的属性“ stateUpdate”(哪个函数)/将数据从父级传递到子级

[英]TypeError: Cannot read property 'stateUpdate' (Which is a function) of undefined / Passing data from Parent to child

I'm having an issue of passing a function from parent to child component in react js . 我在react js有一个功能从父组件传递到子组件。

I have tried to pass the vale to the component as props but it is showing the type error as defined in the question. 我试图将vale作为道具传递给组件,但它显示了问题中定义的type error i am not able to figure out why is it happening. 我不知道为什么会这样。

Is it because of mapping, if so how to solve it because mapping is important. 是因为映射,如果是因为映射很重要,那么如何解决呢?

Parent Component: 父组件:

stateUpdate(){
      alert("hi");
    }
    render() {

          const tabList =  this.state.productMapData.map(function(object, i){
            return <TableList obj={object} ids = {productRegistrationArrId} key={i} 

Error here: 错误在这里:

 parent= {this.stateUpdate.bind(this)}></TableList>
              })
        return (
          <div> 
            <div style={{ marginTop: 10, marginLeft: "10%" }}>
            <Link to="/api/productregistration" className="btn btn-info" onClick = {this.onDeleteDb} >
                Back to List
            </Link>

Child Component: 子组件:

onUpdate(){
        this.props.parent;    
    }

In parent stateUpdate function declare using arrow function then you may not get this issue. 在父stateUpdate函数中使用箭头函数声明,然后可能不会出现此问题。 I have mentioned sample code below please find it 我在下面提到了示例代码,请找到它

stateUpdate =()=> {
  alert("hi");
}

and in child component in update function you have to call parent function like 在更新功能的子组件中,您必须调用父函数,例如

onUpdate=()=>{
        this.props.parent();  
       // here you have to change parent to parent()
    }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 'TypeError: Cannot read property of x of undefined' 将数据从父组件传递到子组件但其他组件正在工作 - 'TypeError: Cannot read property of x of undefined' when passing data from parent to child component but others are working 将 axios 获取的道具从父级传递给子级返回“类型错误:无法读取未定义的属性 &#39;x&#39;” - Passing axios fetched prop from Parent to Child returns “TypeError: Cannot read property 'x' of undefined” TypeError:无法将子组件中未定义的属性“setState”读取到父组件 - TypeError: Cannot read property 'setState' of undefined in child to parent component 使用window.open将数据从父级传递到子级时,为什么会显示“无法读取未定义的属性”元素”? - When passing data from parent to child with window.open, why do I get 'Cannot read property 'elements' of undefined'? 触发云函数时“类型错误:无法读取未定义的属性‘子’” - “TypeError: Cannot read property 'child' of undefined” when triggering cloud function TypeError:无法读取未定义的属性“ child” - TypeError: Cannot read property 'child' of undefined TypeError:无法读取未定义的属性“ parent” - TypeError: Cannot read property 'parent' of undefined 类型错误:无法读取未定义的属性子项 - TypeError: Cannot Read Property child of undefined 开玩笑:TypeError:无法读取未定义的属性“子” - Jest: TypeError: Cannot read property 'child' of undefined TypeError: Cannot read property 'map' of undefined 当我尝试 map 通过从父组件传递到子组件的道具时显示 - TypeError: Cannot read property 'map' of undefined is showing when I'm trying to map over the props passed from parent component to child component
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM