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

How to handle keys which are arrays? #170

Open
RaddishIoW opened this issue Mar 5, 2021 · 1 comment
Open

How to handle keys which are arrays? #170

RaddishIoW opened this issue Mar 5, 2021 · 1 comment

Comments

@RaddishIoW
Copy link

Hi there,

mutateMany only seems to accept key values which are strings. I use SWR with arrays as the keys (e.g. ['/api/user', token]).

How does mutateMany handle this situation? Do I just call mutateMany with the string '/api/user'? Will this correctly mutate keys in the cache that have the key ['/api/user', token]?

@RaddishIoW
Copy link
Author

I ended up using a function to match the key using RegExp, like this:
mutateMany(key => RegExp(***regex to match key***).test(key))

This is probably the best way to do this as it stands, although I think it's probably fragile to changes in the way keys are generated in SWR.
A better fix would be to allow string arrays to be used as keys?

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