FOLASAYO SAMUEL OLAYEMI
SV_D_CURIOUS_SOFTWARE_ENGINEER'S BLOG

SV_D_CURIOUS_SOFTWARE_ENGINEER'S BLOG

What is the children prop in ReactJS?

FOLASAYO SAMUEL OLAYEMI's photo
FOLASAYO SAMUEL OLAYEMI
·Apr 26, 2022·

1 min read

Subscribe to my newsletter and never miss my upcoming articles

Play this article

children is part of the props object passed to components that allows components to be passed as data to other components, providing the ability to compose components cleanly. There are a number of methods available in the React API to work with this prop, such as React.Children.map, React.Children.forEach, React.Children.count, React.Children.only and React.Children.toArray.

A simple usage example of the children prop is as follows:

Code Sample:

function GenericBox({ children }) {
  return <div className="container">{children}</div>
}

function App() {
  return (
    <GenericBox>
      <span>Hello</span> <span>World</span>
    </GenericBox>
  )
}

Note that, children is a prop that allows components to be passed as data to other components. And also, the React API provides methods to work with this prop.

Thanks for reading...

Happy Coding!

 
Share this