【问题标题】:React-Native Passing Parent Function as prop to Child ComponentReact-Native 将父函数作为道具传递给子组件
【发布时间】:2021-05-26 05:18:28
【问题描述】:

我感到非常沮丧,因为似乎没有帖子可以解决我的问题。在父组件中,有一个存储对象列表的数组,以及一个附加到该列表的方法。 [这里有一个片段供参考]

在我的父组件的渲染方法中,我将此方法作为道具传递给我的子组件。

[第 79 行]

https://i.stack.imgur.com/fStiF.png

我的子组件尝试调用上述方法,在它的 render() in render's return, child component

https://i.stack.imgur.com/crN9T.png

但是由于某种原因,我得到一个错误 this.props.addPart is not a function

完整代码:

WaitlistTable.js 1-34

WaitlistTable.js render 34-56

CustomerAdd.js 1-35

CustomerAdd.js call to addPart in render

【问题讨论】:

标签: react-native components


【解决方案1】:

使您的 addPart 函数成为箭头函数

喜欢这个

addPart = (..,..,..) => {...}

【讨论】:

  • 没有改变任何东西
猜你喜欢
  • 2022-01-24
  • 2020-04-23
  • 2018-06-04
  • 2019-07-03
  • 2020-04-22
  • 2019-12-31
  • 2019-07-13
  • 2020-03-12
相关资源
最近更新 更多