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:

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)

Sorry for the confusing name (CommentCellClass is a functional component). We are in the process of converting the class components to functional components in our app.

Answer

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 }) => { ... }

Leave a Reply

Your email address will not be published. Required fields are marked *