簡體   English   中英

當我通過 props 從父組件將變量的值傳遞給子組件時,我收到一個未定義的值

[英]I receive an undefined value when I pass the value of a variable through props from a parent component to a child component

我在 app.js 中創建了一個變量 pointsFilter 並通過道具我將值發送到一個子組件,在這種情況下,該組件是 Map 但是當我想提取值時我得到未定義並且當我在應用程序中執行 console.log 我得到該值,但是當我在 map.js 中執行相同操作時,我得到未定義

應用程序.js

const [pointsFilter, setPointsFilter] = useState(true)

<Map onLongPress={handleLongPress} puntos={puntos} poinstFilter={pointsFilter} />

map.js

    export default ({ onLongPress, puntos, pointsFilter }) => {

  console.log(pointsFilter)

  return (
    <Mapview style={styles.map} onLongPress={onLongPress} >
      {pointsFilter && puntos.map(x => <Marker coordinate={x.coordinate} title={x.name} key={x.name} />)}
    </Mapview>
  )
}

在 app.js 上,您傳遞了點過濾器,在 Map 上,您嘗試提取點過濾器。 在兩邊使用相同的名稱。 此外,我在您的 Map 組件上看不到組件名稱。 您可以將組件創建為

const export default Map= ({ onLongPress, puntos, pointsFilter })

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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