4주차 질답 #28
Replies: 6 comments 9 replies
-
5번 문제
const personAtom = atom((get) => ({
firstName : get(firstNameAtom),
lastName : get(lastNameAtom),
age : get(ageAtom)
}))
const PersonComponent = () => {
const person = useAtom(personAtom)
return <>{person.firstName} {person.lastName}</>
}
|
Beta Was this translation helpful? Give feedback.
-
1번 문제 Q. jotai에서 |
Beta Was this translation helpful? Give feedback.
-
3번문제1-1아래 코드는 React.memo로 메모이제이션된 컴포넌트의 props로 Valtio의 상태(proxy 객체에서 snapshot으로 가져온 값)를 통째로 전달하고 있습니다. const MemoedTodoItem = memo(TodoItem);
const TodoList = () => {
const { todos } = useSnapshot(state);
return (
<div>
{todos.map(todo => (
<MemoedTodoItem key={todo.id} todo={todo} /> // 객체를 통째로 전달하고 있음
))}
</div>
);
};
const TodoItem = ({ todo }) => {
return (
<div>
<input
type="checkbox"
checked={todo.done}
onChange={() => toggleTodo(todo.id)}
/>
<span style={{ textDecoration: todo.done ? "line-through" : "none" }}>
{todo.title}
</span>
<button onClick={() => removeTodo(todo.id)}>Delete</button>
</div>
);
};
const MemoedTodoItem = memo(TodoItem); 1-2 (옵션)위 코드에서 Valtio의 proxy와 snapshot의 동작 방식 때문에 React.memo가 정상적으로 동작하지 않는 이유를 설명해주세요. |
Beta Was this translation helpful? Give feedback.
-
6번 문제Q1. 카운트 버튼을 누르면 값이 1 오르는 컴포넌트가 2개가 있고 countAtom은 1개가 있습니다. Provider라는 Jotai 컴포넌트를 이용하여 const countAtom = atom(0);
const App = () => {
return (
<div>
// App을 완성시켜주세요.
</div>
);
};
const Counter1 = () => {
return (
<div>
<h2>Counter 1</h2>
</div>
);
};
const Counter2 = () => {
return (
<div>
<h2>Counter 2</h2>
</div>
);
};
export default App; |
Beta Was this translation helpful? Give feedback.
-
2번 문제
const [state, setState] = useState({ count: 0 });
const increment = () => {
state.count += 1;
setState(state);
};
|
Beta Was this translation helpful? Give feedback.
-
4번 문제Jotai에서 |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Beta Was this translation helpful? Give feedback.
All reactions