[英]Trouble passing props from functional to functional component
我正在将道具传递给功能组件,但我不断收到错误消息:
const renderItem = ({ item }) => (
<CommentCellClass
key={item.key}
commentLikes={item.commentLikes}
.... more props
我尝试在 CommentCellClass 组件中访问它们:
const CommentCellClass = ({ props, navigation }) => {
const { key, commentLikes } = props;
但我收到以下错误:
TypeError: undefined is not an object (evaluating 'props.key')]
我究竟做错了什么? 道具不是 null(我在将它们传递给 commentCellClass 之前检查过)
抱歉名称令人困惑( CommentCell Class是一个功能组件)。 我们正在将 class 组件转换为我们应用程序中的功能组件。
导航从何而来? 我希望您的代码如下所示:
const CommentCellClass = (props) => {
const { key, commentLikes } = props;
...
}
或者
const CommentCellClass = ({ key, commentLikes }) => { ... }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.