Skip to content
Discussion options

You must be logged in to vote

According to your code that date is an array of shape [startingDate, endingDate], so it might not have referential equality and will possible trigger unnecessary re-renders.

Can you try change your hook and fetcher to:

const { data, error } = useSWR(userToken ? 
  ['/calendar/events', userToken, Array.isArray(date) ? date[0] : date, Array.isArray(date) ? date[1] : date] :
  null,
  fetch
);
export function fetch(path, userToken, from, to) {
  return API.get(path, {
    params: {
      from,
      to,
    },
    headers: {
      Authorization: `Bearer ${userToken}`,
    },
  }).then((data) => data);
}

So the key array can be correctly serialized.

Replies: 1 comment 1 reply

Comment options

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

Answer selected by RSchneider94
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants