React Hooks issues in React 16.7 TypeError: Object(…) is not a function

前端 未结 3 1731
耶瑟儿~
耶瑟儿~ 2020-12-11 02:08

I\'m running the latest version of React and I\'m getting this error I have a simple Component using React Hooks as you can see here :

import React, { useS         


        
相关标签:
3条回答
  • 2020-12-11 02:17

    I tried to use the following in package.json but do not work.

    "react": "16.7.0-alpha.2",
    "react-dom": "16.7.0-alpha.2",
    

    What worked is the following

    "react": "next",
    "react-dom": "next",
    

    EDIT

    React version v16.8.0 has Hooks inside. Use that.

    0 讨论(0)
  • 2020-12-11 02:35

    edit package.json

    "react": "16.7.0-alpha.2",
    "react-dom": "16.7.0-alpha.2",
    "react-router-dom": "4.4.0-beta.6",
    

    and run yarn

    The react released 16.7.0, but there are no react hooks. If you use '^react@16.7.0-alpha.2', remove yarn.lock, it will install react@16.7.0. So you must delete '^' and use 'react@16.7.0-alpha.2'.

    0 讨论(0)
  • 2020-12-11 02:40

    UPDATE

    Hooks are now release as part of React v16.8.0. You can use hooks by upgrading your react version

    See the docs for more details on the APIs


    React 16.7.0 Doesn't contain hooks.

    As per the React blog

    Our latest release includes an important performance bugfix for React.lazy. Although there are no API changes, we’re releasing it as a minor instead of a patch.

    In order to run hooks in your code, refer How to use new Feature Hooks in React?

    0 讨论(0)
提交回复
热议问题