簡體   English   中英

將道具從功能組件傳遞到功能組件時遇到問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM