본문 바로가기
Research/React

useState로 컴포넌트 update하기

by RIEM 2023. 10. 18.

 

// Updating the screen
import './App.css';

import { useState } from 'react';

function MyButton() {
  const [count, setCount] = useState(0);

  function handleClick() {
    setCount(count + 1);
  }
  return <button onClick={handleClick}>{count} sentences</button>;
}

function App() {
  return (
    <div>
      <h1>You Collected</h1>
      <MyButton />
    </div>
  );
}

export default App;

 

댓글