我想将数据从子组件传递到父组件
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>
}
它不起作用。只有当我在Main组件中传递这样的数据时,它才起作用
return <User helloUser={() => helloUser("john") } />
我做错了什么?谢谢!
答案 0 :(得分:0)
我错误地传递了()=>
return <User helloUser={helloUser } />