3주차 질답 #26
Replies: 6 comments 7 replies
-
2번 문제챕터7에 나온 Zustand 라이브러리 내부 구현에 관련된 문제입니다. 아래와 같이 store를 만들고 const store = create(()=> ({
order: 3,
name: 'a',
})) 다음과 같이 불변으로 상태를 변경한다고 했을때, store.setState()는 새 상태와 이전 상태를 병합합니다. store.setState({
order: 2,
})
const userStore = create(() => ({
order: 1,
name: {first: "son", last: "kim" }
}) |
Beta Was this translation helpful? Give feedback.
-
5번 문제
import { useStore } from './store.ts'
const Component = () => {
const { count, text } = useSotre()
return <div>count : { count }</div>
} |
Beta Was this translation helpful? Give feedback.
-
1번 문제 Q. 리렌더링 최적화의 핵심은 컴포넌트에서 state의 어느 부분이 사용될지 지정하는 것입니다. state의 일부분을 지정하는 몇 가지 접근 방식 중 선택자 함수 사용(useSelector)과 속성 접근 감지(useTrackedState)는 구현과 사용 방식에서 어떤 차이가 있을까요? |
Beta Was this translation helpful? Give feedback.
-
3번 문제Q1. Q2. const store = create(() => ({
order: 3,
name: 'a',
}));
store.setState({
order: 2,
}); Zustand의 store.setState()가 내부적으로 JavaScript 객체의 어떤 메서드를 활용하여 만들어진 것일까요? |
Beta Was this translation helpful? Give feedback.
-
6번 문제Q1. // selector.ts
const selector = (state: State) => state.count * 10
// main.ts
import { selector } from './selector'
const Counter = () => {
const count = useStore(selector);
// ...
} Q2. |
Beta Was this translation helpful? Give feedback.
-
Q. zustand를 이용하여 컴포넌트를 만들었습니다. const Total = () => {
const count1 = useStore(selectCount1);
const count2 = useStore(selectCount2);
return (
<div> total : {count1 + count2} </div>
)
} count1과 count2를 더하는 컴포넌트입니다. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions