React-Native 将父函数作为道具传递给子组件

时间:2021-02-23 21:44:42

标签: react-native components

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

在我的父组件的 render 方法中,我将此方法作为 prop 传递给我的子组件。

[第 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

1 个答案:

答案 0 :(得分:0)

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

喜欢这个

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