React Js 中的函数组件在哪里获取 props 和设置 props?
props data coming from the parent component
const [state, setState] = useState({
reportTypesVal: { label: "", value: "" } || props?.reportTypesVal});
为什么我无法将这样的数据设置为reportTypesVal? 如果我尝试在 useEffect 中设置数据,它不会将值设置为 reportTypesVal。 我怎样才能做到这一点?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你的问题有点不清楚,但从标题来看:
我假设您问如何传递道具,这是新测试版文档的示例: https://beta.reactjs.org/learn/passing-props-to-a-component
Your question is a bit unclear, but from the title:
I assume you're asking how to pass props, here is an example on the new beta documentation: https://beta.reactjs.org/learn/passing-props-to-a-component
您应该在子名称函数中实现它。
前任:
You should implement it in the child name function.
EX:
这是将 props 传递到组件中的方式:
这是在组件中检索它的方式:
您可以通过使用状态并将 set 函数作为属性传递来更改组件内部的属性:
在组件内部您可以执行以下操作:
然后单击该按钮它将更改为“randomText2”
This is how you pass props into a component:
This is how you retrieve it in the component:
You can change the property inside of the component by using states and passing the set function as a property:
Inside the component you can do:
Then when you click the button it will change to 'randomText2'