我有这个组件:
import React, { useState, useEffect } from "react";
import ReactDOM from "react-dom";
function App() {
const [count, setCount] = useState(0);
useEffect(() => {
document.title = `You clicked ${count} times`;
});
return (
<div>
<p>You clicked {count} times</p>
<button onClick={() => setCount(count + 1)}>Click me</button>
</div>
);
}
export default App;
因为我想尝试新的阵营钩通过安装建议react@16.8.1
我package.json
,但我得到一个错误:
TypeError: dispatcher.useState is not a function
2 | import ReactDOM from "react-dom";
3 |
4 | function App() {
> 5 | const [count, setCount] = useState(0);
| ^
6 | useEffect(() => {
7 | document.title = `You clicked ${count} times`;
8 | });
我做错了什么?