2.0 KiB
id | title | permalink | prev | next |
---|---|---|---|---|
static-type-checking | Static Type Checking | docs/static-type-checking.html | typechecking-with-prototypes.html | refs-and-the-dom.html |
Static type checkers like Flow and TypeScript identify certain types of problems before you even run your code. They can also improve developer workflow by adding features like auto-completion. For this reason, we recommend using Flow or TypeScript instead of PropTypes
for larger code bases.
Flow
Below are instructions to add Flow to your React application. (You can learn more about using Flow with React here.)
Using Flow with Babel
First install Babel. If you have not already done this, here is a helpful setup guide.
Next install babel-preset-flow
with either Yarn or npm.
yarn add --dev babel-preset-flow
# or
npm install --save-dev babel-preset-flow
Then add flow
to your Babel presets config.
{
"presets": ["flow"]
}
Using Flow with Create React App
Create React App supports Flow by default. Just install Flow and create a .flowconfig
file by running flow init
.
create-react-app my-app
cd my-app
yarn add --dev flow-bin
yarn run flow init
Flow will now be run as part of create-react-app
's scripts.
TypeScript
You can learn more about using TypeScript with React here.
Using TypeScript with Create React App
react-scripts-ts automatically configures a create-react-app
project to support TypeScript. You can use it like this:
create-react-app my-app --scripts-version=react-scripts-ts
You can also try typescript-react-starter.