I hope I'm not repeating a question. I've seen this one: TypeError dispatcher.useState is not a function when using React Hooks, however my App runs fine, it is only an error in Flow:
Cannot import `useState` because there is no `useState` export in `react`.
4| import { useState } from 'react';
I am using 16.7.0-alpha
for my react and react-dom dependencies:
"dependencies": {
...
"react": "^16.7.0-alpha",
"react-dom": "^16.7.0-alpha"
},
This is the only error I get from Flow, other React elements are fine. Is there something wrong with my dependencies?
This is the top of my file:
// @flow
import React from 'react';
import { useState } from 'react';
Edit: I also went into my node_modules/react folder and verified that the useState
function is indeed in there.
I hope I'm not repeating a question. I've seen this one: TypeError dispatcher.useState is not a function when using React Hooks, however my App runs fine, it is only an error in Flow:
Cannot import `useState` because there is no `useState` export in `react`.
4| import { useState } from 'react';
I am using 16.7.0-alpha
for my react and react-dom dependencies:
"dependencies": {
...
"react": "^16.7.0-alpha",
"react-dom": "^16.7.0-alpha"
},
This is the only error I get from Flow, other React elements are fine. Is there something wrong with my dependencies?
This is the top of my file:
// @flow
import React from 'react';
import { useState } from 'react';
Edit: I also went into my node_modules/react folder and verified that the useState
function is indeed in there.
- 1 React typings still not updated – Aleksey L. Commented Nov 1, 2018 at 17:36
2 Answers
Reset to default 4Update Nov 11 2018 - Brian Vaughn from the React team has added Flow types for React hooks and it has been merged - https://github./facebook/flow/pull/7149/
The React Flow types are not yet updated as seen here.
You could make a PR to update it if you are up for it (:
After searching everywhere Found the Solution Use Flow as mentioned by many developers above I tried installing flow and it works
npm i -D flow-babel-webpack-plugin
works for me, but
Also If that not work try once this also
"flow-bin": ">=0.44.2 <1",