-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
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
SWR->TanStack Queryに移行する? #335
Comments
こんな感じで書いていいみたい useQuery({
queryKey: ['todos', todoId],
queryFn: () => fetchTodoById(todoId),
}) |
npm i -D @tanstack/eslint-plugin-query |
SWRの |
queryFnでUndefinedを返却することは出来ない。(反映されない) isErrorで判定する必要あり |
useMutationを使って特定のキャッシュを更新させたい場合 |
タブを再フォーカスした際に、一度実行に失敗したクエリを再実行する為、以下のような問題が発生する。
この問題を解決するためのissue |
フェッチ結果が同じでも再レンダリングされる? 再レンダリングをさせたいプロパティだけ個別で設定しないといけないぽい...? もしその場合は正直SWRに軍配上がりそう |
SWRのように比較してくれないみたい |
データが同じだった場合は再レンダリングされないのが正しい挙動? |
https://tanstack.com/query/v5/docs/framework/react/reference/useQuery
効いてない感じするけど |
Date型がよくないっぽい |
structuralSharing: (oldData, newData) => {
if (JSON.stringify(oldData) === JSON.stringify(newData)) {
return oldData;
}
return newData;
}, これで解決。 SWRはハッシュ化して比較しているのでそれに習ってみる npmパッケージとして公開されていたのでこれを使用する。 |
総評Good
Bad
|
使用感はかなり良かったし、SWRと比べて可読性も良い。 なんとか出来なくもなさそうだが、設計と実装に割く余力が無いため今回は断念。 次回の為にブランチは残しておく |
関連Issue
概要
APIとの通信やキャッシュ、状態管理をSWRで行っているが、
SWRを使って丸めた箇所(swr/client配下)の見通しは悪い気がした。
(コンポーネント使用箇所はかなり見やすいと思うけど)
ReactQueryにした時にどう変わるか、変わった結果移行するのか含めて検証を行いたい
The text was updated successfully, but these errors were encountered: