1、我使用的react和react版本都是16.7版本。
2、我使用的案例是官方react Hooks useState案例。
3、相同的代码,我在我项目中使用webpack等打包工具,但是不生效。
4、在https://codesandbox.io/s/j27q... 是可以的。
5、代码如下
import React,{ useState } from 'react';function Example(props) { // Declare a new state variable, which we'll call "count" const [count, setCount] = useState(0); console.log(count,'-----') return ( <div> <h1 style={{color: 'red', fontSize: 100}}>You clicked {count} times</h1> <button onClick={() => setCount(count + 1)}>Click me</button> </div> ); }export default Example;
小唯快跑啊