Last updated 2017-01-07
This recipe is part of the Flow Cookbook series.
Flow and React are both Facebook projects - so as you might imagine, they work quite well together. React components can take type parameters to specify types for props, default props, and state. Type-checking works well with both functional and class components.
Flow type annotations provide an alternative to
propTypes runtime checks.
Flow’s static checking has some advantages:
- Problems are reported immediately - it is not necessary to run tests that
evaluate every component to identify
- Flow types can be more precise and concise than
- Flow can also check
stateas well as
- In addition to checking that a component gets the correct
props, Flow checks that
statesare used correctly within the component’s
rendermethod, and in other component methods.