Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React. Children as prop

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..)

like image 719
Виталий Заславский Avatar asked Apr 28 '17 12:04

Виталий Заславский


People also ask

Can you pass children as a prop?

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.

How do you prop kids in React?

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.

What type is React props children?

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”.

Can you pass React component as prop?

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.


1 Answers

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

like image 56
Lingaraju E V Avatar answered Sep 26 '22 04:09

Lingaraju E V