Unsure how to pass optional params using the object syntax #544
-
Hello 👋, and thank you for the fantastic library. It has really helped my team simplify how we work with server cache! I have a question. In the README example, we can see the following snippet: function Todo({ todoId, preview }) {
const { status, data, error } = useQuery(
// These will be used as the query key
['todo', todoId],
// These will get passed directly to our query function
[
debug,
{
foo: true,
bar: false,
},
],
fetchTodoById
)
} now if we were to write it as follows const { status, data, error } = useQuery({
queryFn: fetchTodoById,
queryKey: ['todo', todoId],
config: {
staleTime: Infinity,
},
}); where should the optional variables be included? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
The
so we rule it out. |
Beta Was this translation helpful? Give feedback.
-
It is my understanding that the useQuery({
queryKey: ['todo', 7],
queryFn: fetchTodos,
variables: [],
config: {},
}) |
Beta Was this translation helpful? Give feedback.
It is my understanding that the
variables
key refers to the variables that dont affect the key, so this is the right place to add anything that shouldn't affect the caching mechanism.