3. useState with object
다음 컴포넌트는 렌더링이 될 때마다 콘솔에 "re-rendered"를 출력한다.
function Counter() {
const [count, setCount] = useState(0);
const [countObj, setCountObj] = useState({ count: 0 });
console.log("re-rendered");
return (
<div>
<button onClick={() => setCount(0)}>update count</button>
<button onClick={() => setCountObj({ count: 0 })}>update countObj</button>
</div>
);
}
"update count" 버튼을 눌렀을 때, 리렌더링이 일어나는가?
"update countObj" 버튼을 눌렀을 때, 리렌더링이 일어나는가?