O'Reilly logo

React 16 Tooling by Adam Boduch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parents with one child

For some components, it makes no sense to have more than one child. For these cases, you would use the React.Element type instead of the React.ChildrenArray type:

// @flow
import * as React from 'react';
import Child from './Child';

type Props = {
  children: React.Element<Child>,
};
 
const ParentWithOneChild = ({ children }: Props) => (
  <section>
    <h2>Parent With One Child</h2>
    {children}
  </section>
); 
export default ParentWithOneChild; 

As with the example before this one, you can still specify the type of child component that is allowed. In this case, the child component is called Child, imported from './Child'. Here's how you would pass this component a child component:

<ParentWithOneChild> <Child /> </ParentWithOneChild> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required