-
Bug reportWhen using Expected BehaviorI would expect Code Examplehttps://codesandbox.io/s/swr-basic-forked-6srjsk?file=/src/App.js |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
@cbejensen export async function addTodo(todo) {
await delay();
todos = [...todos, todo];
} https://swr.vercel.app/docs/mutation#parameters To fix that, you can disable the |
Beta Was this translation helpful? Give feedback.
-
Ah, just my misunderstanding then - thank you! |
Beta Was this translation helpful? Give feedback.
@cbejensen
In your
api.js
,addTodo
returns nothing, andpopulateCache
istrue
(the default value ofmutate
), which means that SWR updates its cache data withundefined
, souseSWR
returnsundefined
when the next revalidation.https://swr.vercel.app/docs/mutation#parameters
To fix that, you can disable the
populateCache
option atmutate
or return the updated data fromaddTodo
.