728x90
import React from "react"
import { useState, useEffect } from "react"
export default function App(){
const [num, setNum] = useState(0);
useEffect(() => {
console.log("effect")
document.querySelector("#up").addEventListener("click", onIncrease);
}, []);
function onIncrease(){
setNum(num + 1);
}
return(
<>
<h1>App</h1>
<h1>{num}</h1>
<button id="up">+</button>
</>
)
}
'단순 코드 기록 > React' 카테고리의 다른 글
React_useMemo(고정값) (0) | 2024.03.19 |
---|---|
React_memo (0) | 2024.03.19 |
React_useEffect Hook (0) | 2024.03.19 |
React_reducer_자식창 연동 ADD/DEL (0) | 2024.03.19 |
React_Context(Single/Multi) (0) | 2024.03.18 |