React Hook 之 useState

2020-03-28  本文已影响0人  FAKEEER
import React, { useState } from 'react';

function Example() {
  // 声明一个叫 "count" 的 state 变量
  const [count, setCount] = useState(0);
  return (
    <div>
      <p>You clicked {count} times</p>
      <button onClick={() => setCount(count + 1)}>
        Click me
      </button>
    </div>
  );
}
上一篇下一篇

猜你喜欢

热点阅读