<!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);
};
console.log("rendered");
console.log(counter);
return(
<div>
<h3>클릭횟수 : {counter}</h3>
<button onClick={onClick}>누르시오</button>
</div>
);
}
ReactDOM.render(<App />,root);
</script>
</html>
state 값이 바뀌면 알아서 리랜더링을 해준다.