<!DOCTYPE html>
<html>
<body>
<div id="root"></div>
</body>
<script src="https://unpkg.com/react@17.0.2/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom@17.0.2/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
<script type="text/babel">
const root = document.getElementById("root");
function App() {
const [counter,setCounter] = React.useState(0);
const onClick = () =>{
//setCounter(counter+1);
setCounter((current) => current+1);
};
return(
<div>
<h3>클릭횟수 : {counter}</h3>
<button onClick={onClick}>누르시오</button>
</div>
);
}
ReactDOM.render(<App />,root);
</script>
</html>
//setCounter(counter+1);
setCounter((current) => current+1);
위방법은 직접 값을 주는방법이고
아래방법은 current가 함수를 전달해주는 방법이다.