TypeError dispatcher.useState is not a function when using React Hooks

前端 未结 7 770
失恋的感觉
失恋的感觉 2020-12-06 09:04

I have this component:

import React, { useState, useEffect } from \"react\";
import ReactDOM from \"react-dom\";

function App() {
  const [count, setCount]          


        
7条回答
  •  鱼传尺愫
    2020-12-06 09:32

    You may get same error when using jest. So to fix the error I had to update react-test-renderer to have the same version as react and react-dom

    yarn add -D react-test-renderer@next
    

    Or

    npm i react-test-renderer@next
    

    All react, react-dom and react-test-renderer should contain same version

    "react": "^16.7.0-alpha.0",
    "react-dom": "^16.7.0-alpha.0",
    "react-test-renderer": "^16.7.0-alpha.0"
    

提交回复
热议问题