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

Validating component state

You can validate the properties of functional React components by typing the props argument that's passed to the component. Some of your components will have state and you can validate a component's state much the same as with properties. You can create a type that represents the state of your component, and pass this to Component as a type argument.

Let's take a look at a container component that has state that is used and manipulated by a child component:

// @flow 
import React, { Component } from 'react'; 
import Child from './Child'; 
 
type State = { 
  on: boolean 
}; 
 
class Container extends Component<{}, State> { 
  state = { 
    on: false 
  } 
 
  toggle = () => { 
    this.setState(state => ({ 
      on: !state.on 
    }));
 } render() { return ...
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