Skip to content
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

Making changes to data prop incorrectly updates the cache #3032

Open
akteigland opened this issue Oct 28, 2024 · 0 comments
Open

Making changes to data prop incorrectly updates the cache #3032

akteigland opened this issue Oct 28, 2024 · 0 comments

Comments

@akteigland
Copy link

Bug report

Description / Observed Behavior

I made changes to data returned from useSWR, to format the data. This updated the SWR cache with the formatted data, which later resulted in a different useSWR hook returning the formatted data, which is incorrect.

Expected Behavior

I would expect that any changes made to the data object be made locally only and not propagated to the SWR cache.

Repro Steps / Code Example

CodeSandbox

Additional Context

I don't think making changes directly to data is great practice anyway, but it can be fairly easy to do so accidentally. In my case I had mistakenly expected a lodash function to return a copy of the data and not the data object itself. While I understand why this would make changes to data locally, I was surprised to find this affected the cache as I would not expect changes outside of the fetcher function to make changes to the cache.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant