Skip to Content
React 16 Tooling
book

React 16 Tooling

by Adam Boduch, Christopher Pitt
April 2018
Intermediate to advanced content levelIntermediate to advanced
298 pages
6h 34m
English
Packt Publishing
Content preview from React 16 Tooling

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro React 16

Pro React 16

Adam Freeman

Publisher Resources

ISBN: 9781788835015Supplemental Content