Languages

React - how to set child component text between tags from parent component using props?

0 points
Asked by:
Zoya-Gaines
653

How can I set child component text between tags from a parent component using props?

Let's say I have a component:

Now, what I want to do is to set "some text" between <div> tags from another component.

Can you help me with that?

1 answer
0 points
Answered by:
Admin Dirask Community
4380

You can use props.children to set the child component text from parent using props.

Practical example

In this example App is a parent component and MyComponent is a child.

 

References

  1. Composition vs Inheritance – React
0 commentsAdd comment
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join