1주차 질답 #22
choisohyun
started this conversation in
리액트 훅을 활용한 마이크로 상태 관리
1주차 질답
#22
Replies: 6 comments 7 replies
|
4번 질문
|
2 replies
|
1번
|
1 reply
6번 질문Q. 지역 상태를 효과적으로 사용하는 방법 중에서 불필요한 리렌더링을 방지하기 위해 어떤 방법을 사용할 수 있을까요? const Parent = () => {
const [count, setCount] = useState(0);
return(
<>
<Child1 count={count} />
<NoEffect />
</>
);
}; |
1 reply
3번 질문아래 코드에서, 버튼을 빠르게 두 번 클릭했을 때 1번 코드와 2번 코드의 동작에서의 차이와, 그 이유를 말씀해주세요. // 어떤 컴포넌트 내부
const [count, setCount] = useState(0);
const handleClickAddCount = () => {
// 1번
setCount((count) => count + 1);
// 2번
setCount(() => count + 1);
};
return <button onClick={handleClickAddCount}>버튼</button>; |
1 reply
5번Q1. 지역 상태를 언제 사용해서는 안될까요?Q2. 다음 예제에서 버튼을 클릭하면 화면상에 변화가 없는 이유가 무엇일까요?const Component = () => {
const [state, setState] = useState({count: 0})
return <div>
<button onClick={() => setState({count:1})}>
{state.count}
</button>
</div>
} |
1 reply
|
7번 질문
const init = () => 0;
const Component = () => {
const [count, setCount] = useState(init);
return (
<div>
{count}
<button onClick={(c) => setCount(c + 1)}>
Increment Count
</button>
</div>
);
};
|
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
All reactions