Skip to content
Discussion options

You must be logged in to vote

@cbejensen
In your api.js, addTodo returns nothing, and populateCache is true (the default value of mutate), which means that SWR updates its cache data with undefined, so useSWR returns undefined when the next revalidation.

export async function addTodo(todo) {
  await delay();
  todos = [...todos, todo];
}

https://swr.vercel.app/docs/mutation#parameters

To fix that, you can disable the populateCache option at mutate or return the updated data from addTodo.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by cbejensen
Comment options

You must be logged in to vote
1 reply
@koba04
Comment options

koba04 May 4, 2023
Collaborator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #2598 on May 04, 2023 13:54.