【发布时间】:2020-12-29 18:08:49
【问题描述】:
我正在尝试将参数(项目,它是 FlatList 中的数据项)传递给道具中的箭头函数。 Popover 是一个 react-native-ui-kitten 元素。我的代码如下:
function PostRenderItem({ item }){
const [deleting, setDelete] = useState(false);
//item is accessible at this point
return(
//item is accessible at this point
<Popover
visible={deleting}
anchor={(item) => {
return(
<Text>{item.content}</Text>
//item undefined at this point
)
}}>
<Button>Delete me!</Button>
</Popover>
)
};
这里的问题是 item 在声明为锚属性的箭头函数中未定义。这里的正确解决方案是什么?
【问题讨论】:
-
你不需要包含 item 作为箭头函数参数,因为上面已经有了它
标签: javascript react-native react-native-ui-kitten