Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
805 views
in Technique[技术] by (71.8m points)

reactjs - React Hooks issues in React 16.7 TypeError: Object(...) is not a function

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

import React, { useState } from "react";

const AppFunction = () => {
  const [count, setCount] = useState(0);

  const incrementCount = () => {
    setCount(count + 1);
  };
  return (
    <div>
      <h1>Count:{count} </h1>
      <button onClick={incrementCount}>Click Me</button>
    </div>
  );
};

export default AppFunction;

Everything i've found about it on stack overflow says to upgrade the libraries but I have the latest version (16.7.0) and have tried the alpha version with no luck , what am i doing wrong?

package.json

"dependencies": {
    "react": "^16.7.0",
    "react-dom": "^16.7.0",
    "react-scripts": "2.1.1"
  },
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...