简体   繁体   English

将道具从功能组件传递到功能组件时遇到问题

[英]Trouble passing props from functional to functional component

I am passing props to a functional component, but I keep getting an error:我正在将道具传递给功能组件,但我不断收到错误消息:

const renderItem = ({ item }) => (

    <CommentCellClass
      key={item.key}
      commentLikes={item.commentLikes}
      .... more props

I try and access them in the CommentCellClass component:我尝试在 CommentCellClass 组件中访问它们:

const CommentCellClass = ({ props, navigation }) => {
  const { key, commentLikes } = props;

But I get the following error:但我收到以下错误:

   TypeError: undefined is not an object (evaluating 'props.key')]

What am I doing wrong?我究竟做错了什么? The props are not null (I checked before I passed them to commentCellClass)道具不是 null(我在将它们传递给 commentCellClass 之前检查过)

Sorry for the confusing name (CommentCell Class is a functional component).抱歉名称令人困惑( CommentCell Class是一个功能组件)。 We are in the process of converting the class components to functional components in our app.我们正在将 class 组件转换为我们应用程序中的功能组件。

Where does navigation come from?导航从何而来? I would expect your code to look like this:我希望您的代码如下所示:

const CommentCellClass = (props) => {
  const { key, commentLikes } = props;
  ...
}

or或者

const CommentCellClass = ({ key, commentLikes }) => { ... }

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM