最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论