React에서 State 사용하는 법
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react'; | |
const Counter = () => { | |
const [number, setNumber] = useState(0); | |
handleIncrease = () => { | |
setNumber(number + 1); | |
}; | |
handlerDecrease = () => { | |
setNumber(number - 1); | |
}; | |
return ( | |
<div> | |
<h1>counter</h1> | |
<p>{number}</p> | |
<button onClick={handleIncrease}>+</button> | |
<button onClick={handleDecrease}>-</button> | |
</div> | |
) | |
} | |
export default Counter; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment