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

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.

相关问题 当我有多个子组件时,如何将值从子组件传递给父组件? - How could i pass a value from a child component to parent, when i have multiple child components? 我可以在 Astro 中将道具从子组件传递给父组件吗? - Can i pass props from a child component to parent in Astro? 使用 React Hooks,当我将 prop 从父组件传递给子组件时,子组件中的 prop 未定义 - Using React Hooks, when I pass down a prop from parent to a child component, the prop in the child component is undefined ReactJS:子组件中未定义道具,我无法通过父组件传递道具参数 - ReactJS: Props is undefined in child component and I can't pass props parameters throught parent TypeError: Cannot read property 'map' of undefined 当我尝试 map 通过从父组件传递到子组件的道具时显示 - TypeError: Cannot read property 'map' of undefined is showing when I'm trying to map over the props passed from parent component to child component 如何使用 function 将值从子组件传递到父组件? - How do i pass a value from child component to parent component using function? 如何通过道具[REACT.JS]将图片网址从父组件传递到子组件 - How can I pass image url from parent component to child component via props [REACT.JS] 将值从子级传递到父级组件中 - pass value from child to parent component in react 如何在子组件中从父组件重置道具? - How do I reset props from a parent component in a child component? 道具值没有在vue中将更新的值从父组件发送到子组件 - props value not sending the updated value from parent to child component in vue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM