将道具传递给道具。
const Component1 = (props) => {
const [myState, setMyState] = useState('hello world');
const ChildComponent = props.children.type;
return (
<div>
<ChildComponent data={myState} />
</div>
)
}
export default Component1;
我想要从component1到props.children的通过道具,我想问我的方法是正确的吗? ; component1 /&gt; < /code>我不想从应用程序组件中通过props我希望从component1传递给props.children。
const Component1 = (props) => {
const [myState, setMyState] = useState('hello world');
const ChildComponent = props.children.type;
return (
<div>
<ChildComponent data={myState} />
</div>
)
}
export default Component1;
i want pass props from Component1 to props.children, i want to ask my this approach is right ?, i am reusing Component1 in my code and passing components to Component1 like this <Component1><Component2 /><Component1 />
i want not pass props from App component i want pass props from Component1 to props.children.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一种非常复杂的方法。根据经验,您应该在单独的文件中具有单独的组件。
我不清楚您要编码的内容,但根据我的推论,这就是我的处理方式。
我将拥有单独的
&lt; childComponent /&gt; < /code>和
&lt; component1 /&gt; < /code>。
在
&lt; component1/&gt;
中,我将渲染&lt; childcomponent/&gt;
您可以清楚地看到
component1 是一个冗余组件。
但是,如果
&lt; component1/&gt;
用作事件That's a pretty convoluted approach. As a rule of thumb, you should have separate components in separate files.
I am not clear about what you are trying to code, but from what I deduced, here's how I'd approach it.
I will have separate
<ChildComponent />
and<Component1 />
.Inside the
<Component1 />
, I will render the<ChildComponent />
You can see clearly that
Component1
is a redundant component.However, if
<Component1/>
acts as a HOC, you can wrap theChildComponent
inside of it as