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
Support arrays and objects as query keys #85
Comments
I'm working on a full react-query integration to make this and all other nice features available in Rakkas. Until then you can use, e.g., |
This won't invalidate |
No but this will: client.invalidateQueries((k) => k.startsWith(`["items"`)) as a workaround for now. Please bear with me as I experiment with various APIs for plugins. Real |
Take your time, all is good :) export const createQueryKey = (key: (string | number)[]) => JSON.stringify(key);
export const invalidateQuery = (
client: QueryClient,
key: (string | number)[]
) => {
client.invalidateQueries((_key) => {
const isJson = _key.startsWith("[") && _key.endsWith("]");
if (!isJson) return false;
try {
const parsed = JSON.parse(_key);
if (!Array.isArray(parsed)) return false;
return key.every((k, i) => k === parsed[i]);
} catch (error) {
return false;
}
});
}; |
Sometimes, a string just isn't enough to reliably represent a query key. In a case where you have many params in a request, such as filters, and sorting options, it becomes cumbersome to have to convert it all into a string, while also ensuring that the order of the concatenation is consistently preserved.
React query allows arrays of strings and objects as query keys. It would be nice to have that convenience in Rakkas as well.
The text was updated successfully, but these errors were encountered: