英文:
Problem trying to pass props to child component
问题
I'm making my first project with React and everything is working fine but one simple thing... but I don't know what I'm missing and I think I tried everything.
I'm trying to pass some props/info to a child component like this but it seems it's not receiving any info. What am I missing here? That console.log in the child component is throwing an empty object whatever I try to do.
In my main App.jsx I have this code:
<Popup miData={{title:'Hello world', text:'Lorem ipsum...'}}/>
and that child component is something like:
import React from "react"
const Popup = (miData) => {
   console.log(miData)
    return (
        html code here is fine, component is being rendered correctly
    )
}
export default Popup
(both components are being rendered fine, everything works fine but this passing props thing)
英文:
I´m making my first project with React and everything is working fine but one simple thing... but I don´t know what I´m missing and I think I tried everything.
I´m trying to pass some props/info to a child component like this but it seems it´s not receiving any info. What am I missing here? That console.log in the child component is throwing an empty object whatever I try to do.
In my main App.jsx I have this code:
<Popup miData={{title:'Hello world', text:'Lorem ipsum...'}}/>
and that child component is something like:
import React from "react"
const Popup = (miData) => {
   console.log(miData)
    return (
        html code here is fine, component is being rendered correctly
    )
}
export default Popup
(both components are being rendered fine, everything works fine but this passing props thing)
答案1
得分: 1
尝试在你的返回语句中添加React片段。
import React from "react";
const Popup = (miData) => {
   console.log(miData);
    return (
      <>
        这里的HTML代码没问题,组件被正确渲染了
      </>
    );
}
export default Popup;
在我的沙盒上运行正常。
英文:
try adding react Fragments in your return statement
import React from "react"
const Popup = (miData) => {
   console.log(miData);
    return (
      <>
        html code here is fine, component is being rendered correctly
      </>
    );
}
export default Popup;
Its working for me on my sandbox
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论