We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useState(new Store()) vs useState(() ⇒ new Store())
onSuccess
onError
onSettled
Breaking React Query's API on purpose
BAD
export function useTodos() { const [todoCount, setTodoCount] = React.useState(0); const { data: todos } = useQuery({ queryKey: ["todos", "list"], queryFn: fetchTodos, //😭 please don't onSuccess: (data) => { setTodoCount(data.length); }, }); return { todos, todoCount }; }
GOOD
export function useTodos() { const { data: todos } = useQuery({ queryKey: ['todos', 'list'], queryFn: fetchTodos, }) const todoCount = todos?.length ?? 0 return { todos, todoCount } }
만약 상태가 서버에서 받은 값에 의존할 수 밖에 없다면 (ex. 수정 form)
export const EditForm = () => { const [title, setTitle] = useState(); const { data: formData } = useQuery({ queryKey: ["data", "form"], queryFn: fetchData, }); // title 동기화 const handleChange = (e) => { setTitle(e.target.value); }; return ( <form> <input value={title} onChange={handleChange} /> </form> ); };
The text was updated successfully, but these errors were encountered:
Sorry, something went wrong.
bada308
No branches or pull requests
[우아한타스] 10장. 상태 관리
게으른 초기화
파생된 값은 상태가 아니다
onSuccess
,onError
,onSettled
콜백 제거Breaking React Query's API on purpose
BAD
GOOD
만약 상태가 서버에서 받은 값에 의존할 수 밖에 없다면 (ex. 수정 form)
The text was updated successfully, but these errors were encountered: