Add queryKey to hooks payload #686
-
What about adding queryKey to hook payload? const { data, status, queryKey } = useQuery('todos', fetchTodos)
console.log(queryKey) // 'todos' With this, we can create custom hooks and always have the queryKey to make other operations: // todos.js
const useTodos = () => {
return useQuery('todos', fetchTodos)
}
// another-file.js
const MyComponent = () => {
const { data, status, queryKey } = useTodos()
const handleOnClick = () => {
queryCache.removeQueries(queryKey)
}
return (
<div>
<button onClick={handleOnClick}>Remove Todos</button>
<ul>
{todos.map(todo => <li key={todo.id}>{todo.label}</li>)}
</ul>
</div>
)
} |
Beta Was this translation helpful? Give feedback.
Answered by
tannerlinsley
Jul 1, 2020
Replies: 1 comment 2 replies
-
|
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
MichaelDeBoey
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
useQuery().query.queryKey