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

Object property values

In the preceding section, you learned how to check for primitive property types. React components can also accept objects with primitive values—and other objects. If your component is expecting an object as a property value, you can use the same approach as you did for primitive values. The difference is how you structure your Props type declaration:

// @flow 
import React from 'react'; 
 
type Props = { 
  person: { 
    name: string, 
    age: number 
  } 
}; 
 
const Person = ({ person }: Props) => ( 
  <section> 
    <h3>Person</h3> 
    <p><strong>Name: </strong>{person.name}</p> 
    <p><strong>Age: </strong>{person.age}</p> 
  </section> 
); 
 
export default Person; 

This component expects a person property which is an object. Further, it expects this object ...

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