I know how to pass children to React component:
<Button block
href={url}
target="_blank"
bsStyle="primary"
bsSize="xsmall">Open This Wonderful Link</Button>
But can I use this way:
<Button block
href={url}
target="_blank"
bsStyle="primary"
bsSize="xsmall"
children="Open This Wonderful Link" />
It works, but is this normal? Can I use this way every time?
P.S. Sorry for my poor English..)
As said, there is no way passing props from a child to a parent component. But you can always pass functions from parent to child components, whereas the child components make use of these functions and the functions may change the state in a parent component above.
By invoking them between the opening and closing tags of a JSX element, you can use React children for entering data into a component. The React children prop is an important concept for creating reusable components because it allows components to be constructed together.
Essentially, props. children is a special prop, automatically passed to every component, that can be used to render the content included between the opening and closing tags when invoking a component. These kinds of components are identified by the official documentation as “boxes”.
React elements like <Contacts /> and <Chat /> are just objects, so you can pass them as props like any other data. This approach may remind you of “slots” in other libraries but there are no limitations on what you can pass as props in React.
Yes, children
is like any other prop
and can be used as a prop
to render child components, instead of nesting child components in the respective element
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With