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 specific children types

You can tell Flow that a component should only work with specific types of child components. Let's say that you have a Child component, and this is the only type of component that should be allowed as a child of the component you're working on. Here's how you can tell Flow about this constraint:

// @flow 
import * as React from 'react'; 
import Child from './Child'; 
 
type Props = { 
  children: React.ChildrenArray<React.Element<Child>>, 
}; 
 
const Parent = ({ children }: Props) => ( 
  <section> 
    <h2>Parent</h2> 
    {children} 
  </section> 
); 
 
export default Parent; 

Let's start with the first import statement:

 import * as React from 'react'; 

The reason that you want to import the asterisk as React is because this will ...

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