繁体   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