加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

reactjs – React 16.7中的React Hooks问题TypeError:Object(…

发布时间:2020-12-15 20:14:22 所属栏目:百科 来源:网络整理
导读:我正在运行最新版本的React,我收到了这个错误 我有一个使用React Hooks的简单组件,如下所示: import React,{ useState } from "react";const AppFunction = () = { const [count,setCount] = useState(0); const incrementCount = () = { setCount(count +
我正在运行最新版本的React,我收到了这个错误

enter image description here


我有一个使用React Hooks的简单组件,如下所示:

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;

我在堆栈溢出时发现的所有内容都说升级库但是我有最新版本(16.7.0)并尝试了没有运气的alpha版本,我做错了什么?

的package.json

"dependencies": {
    "react": "^16.7.0","react-dom": "^16.7.0","react-scripts": "2.1.1"
  },

解决方法

UPDATE

Hook现在作为React v16.8.0的一部分发布.您可以通过升级您的反应版本来使用挂钩

有关API的更多详细信息,请参见docs

React 16.7.0不包含钩子.

按照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.

要在代码中运行挂钩,请参阅How to use new Feature Hooks in React?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读