Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to install flow type correctly for react [email protected]+?

I've googled many sites but cannot found a tutorial that actually works for react-native + flow type.

There was flow installation guide from [email protected] document, but it's gone in [email protected].

However, it comes up again in Running Tests and Contributing, I tested to run npm run flow but not working, and yet it doesn't say how to make it works. It's possibly been a missing part inside of react-native documentation.

What I need is to run flow correctly with react-native. Auto-check flow every time I reload the page with ⌘R would be the best.

like image 798
Val Avatar asked Jul 19 '17 07:07

Val


People also ask

How do you use flow in React Native?

Let's get started We start by initializing a new React Native project (without Expo) by running: npx react-native init flow in our terminal where 'flow' is the name of the project. This can be any valid name you want. Try and run the bare app on your device or emulator.

Should I use flow in React Native?

Flow will help you prevent bugs and allow for better code documentation among other things. A lot of the React Native documentation and source code already also uses flow, so there has never been a better time to start using it!


1 Answers

I just finished covering half of our project by flow and we use RN 0.44.0.

The tricky part is: do you also want to know errors inside node_modules, someone says those errors are helpful.

Anyway, I disable the error in node_modules, and here is my .flowconfig:

[ignore]

<PROJECT_ROOT>/node_modules/.*
<PROJECT_ROOT>/flowLibs.js
.....
[include]

[libs]
./flowLibs.js
.....
[lints]
[options]

You should install flow first if you not setup correctly,

npm install --save-dev flow-bin

and also run this in you project root after install:

npm run flow init

If npm run flow init does not work, just add "flow": "flow" in npm scripts.

After init, put my .flowconfig in your project .flowconfig file.

Then create a js file flowLibs.js and if npm run flow check cause your any error like Module_Name. Required module not found

Write down code in flowLibs.js:

declare module 'Module_Name' {  declare var exports: any;  };

After that, you should be good to go with you project now.

BTW, don't forget add //@flow on the top of the file which you want to check type.

like image 190
Tyreal Gray Avatar answered Dec 07 '22 22:12

Tyreal Gray