-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Closed
Description
Sometimes, we have a static dependency that we read from e.g. react context, like an api:
const useFoo = () => {
const api = useApi();
return useQuery({
queryKey: ['foo'],
queryFn: () => api.fetchFoo(),
})
}
this api is injected via react-context, but it's stable and not really changing. We mainly have it context to provide a different API for testing.
The eslint-plugin-query complains here rightfully that api should be added to the QueryKey, but we can't really do that - it's an axios instance that is not serializable. It's also not intended to be added to the key. For us, it's essentially the same as:
import api from 'api'
const useFoo = () => {
return useQuery({
queryKey: ['foo'],
queryFn: () => api.fetchFoo(),
})
}
Of course, the linter doesn't know that this dependency is "stable". Maybe we could have an option on the eslint plugin that defines known exceptions? @Newbie012 what do you think?