Before you can start implementing type-safe React components, you need to install and initialize Flow. I'll show you how this is done with a create-react-app
environment, but the same steps can be followed for almost any React environment.
You can install Flow globally, but I would recommend installing it locally, along with all the other packages that your project depends on. Unless there's a good reason to install something globally, install it locally. This way, anyone installing your application can get every dependency by running npm install
.
To install Flow locally, run the following command:
npm install flow-bin --save-dev
This will install the Flow executable locally to your project and will update your package.json
so that Flow is installed as a dependency of your project. Now let's add a new command to package.json
so that you can run the Flow type checker against your source code. Make the scripts
section look like this:
"scripts": { "start": "react...