April 2018
Intermediate to advanced
298 pages
6h 34m
English
It's perfectly normal to pass functions from one component to another as a property. You can use Flow to ensure that not only are functions passed to the component, but also that the correction type of function is passed.
Let's examine this idea by looking at a common pattern in React applications. Let's say that you have the following Articles component that renders Article components:
// @flow import React, { Component } from 'react'; import Article from './Article'; type Props = {}; type State = { summary: string, selected: number | null, articles: Array<{ title: string, summary: string}> }; class Articles extends Component<Props, State> { state = { summary: '', selected: null, articles: [ { title: 'First Title', ...