我有这个组件:
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;
因为我想通过在 my中安装来尝试新的React hooks提案,但是我收到了一个错误: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 | });
我做错了什么?