【问题标题】:pass parameters to function in parent component [duplicate]将参数传递给父组件中的函数[重复]
【发布时间】:2020-04-29 12:56:47
【问题描述】:

我想将数据从子组件传递给父组件

const Main () => {
    const helloUser(name) => console.log("hello, name)
    return <User helloUser={() => helloUser } />
}

const User (props) => {
    const { helloUser } = props
    helloUser("john")
    return <p>User component</p>
}

它不起作用。它只有在我在主组件中传递这样的数据时才有效

return <User helloUser={() => helloUser("john") } />

我做错了什么?谢谢!

【问题讨论】:

    标签: javascript reactjs


    【解决方案1】:

    我错误地传递了 () =>

    return <User helloUser={helloUser } />
    

    【讨论】:

      猜你喜欢
      • 2022-01-26
      • 2013-05-21
      • 2012-11-13
      • 1970-01-01
      • 2014-01-10
      • 2020-11-23
      • 1970-01-01
      • 2011-03-24
      • 1970-01-01
      相关资源
      最近更新 更多