April 2018
Intermediate to advanced
298 pages
6h 34m
English
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 ...