[英]I receive an undefined value when I pass the value of a variable through props from a parent component to a child component
I create a variable pointsFilter in app.js and through props I send the value to a child component in this case the component is Map but when I want to extract the value I get undefined and when i do a console.log in app i get the value but when i do the same in map.js i get undefined我在 app.js 中创建了一个变量 pointsFilter 并通过道具我将值发送到一个子组件,在这种情况下,该组件是 Map 但是当我想提取值时我得到未定义并且当我在应用程序中执行 console.log 我得到该值,但是当我在 map.js 中执行相同操作时,我得到未定义
app.js应用程序.js
const [pointsFilter, setPointsFilter] = useState(true)
<Map onLongPress={handleLongPress} puntos={puntos} poinstFilter={pointsFilter} />
map.js 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>
)
}
On app.js you pass poinstFilter and on Map, you try to extract pointsFilter.在 app.js 上,您传递了点过滤器,在 Map 上,您尝试提取点过滤器。 Use the same name on both sides.
在两边使用相同的名称。 Moreover, I don't see the component name on your Map component.
此外,我在您的 Map 组件上看不到组件名称。 You may create components as
您可以将组件创建为
const export default Map= ({ onLongPress, puntos, pointsFilter })
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.