javascript - "Cannot import useState because there is no useState export in react" (Flow with React Hooks) - S

I hope I'm not repeating a question. I've seen this one: TypeError dispatcher.useState is not

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.

Share Improve this question edited Nov 25, 2018 at 20:03 Yangshun Tay 53.2k33 gold badges123 silver badges150 bronze badges asked Nov 1, 2018 at 17:02 P FusterP Fuster 2,3442 gold badges22 silver badges32 bronze badges 1
  • 1 React typings still not updated – Aleksey L. Commented Nov 1, 2018 at 17:36
Add a ment  | 

2 Answers 2

Reset to default 4

Update 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",

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742387405a4434333.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信