0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SWRのmutateはSSGとSSRでは使えないのか

Last updated at Posted at 2022-02-09

結論 : SSRでデータ取得してSWRConfigを用いたデータの状態管理を行なっている際は、mutateは行えないと思っていたが、なんとかなった。

SSRやSSGのpre-renderingでは既にデータ取得してしまっているため、useSWRを使うタイミングではデータがある状態のため、useSWRの第二引数にfetcher関数が必要でない。

原因を考える

mutateをするにはfetcher関数が必要になってくる。
つまり、第二引数を必要としないSSGやSSRでのデータのfetch方法ではmutateが行えない。

対処1: SSR,SSGでfetchする方法からfetcher関数でデータをfetchする方法にきり変えたところ、mutateが作動した。

対処2: mutateの引数にfethcer関数を使えば、再検証は行えた。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?