8000 Update react-query syntax to v5 by simon-johansson · Pull Request #920 · encoredev/encore · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Update react-query syntax to v5 #920

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

Merged
merged 1 commit into from
Oct 23, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions docs/how-to/integrate-frontend.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ import {
useQueryClient,
QueryClient,
QueryClientProvider,
} from 'react-query'
import Client from '../encore-client'
} from '@tanstack/react-query'
import Client, { todo } from '../encore-client'

// Create a Encore client
const encoreClient = new Client(window.location.origin);
Expand All @@ -86,20 +86,24 @@ function Todos() {
const queryClient = useQueryClient()

// Queries
const query = useQuery('todos', encoreClient.todo.List)
const query = useQuery({
queryKey: ['todos'],
queryFn: () => encoreClient.todo.List()
})

// Mutations
const mutation = useMutation(encoreClient.todo.Add, {
const mutation = useMutation({
mutationFn: (params: todo.AddParams) => encoreClient.todo.Add(params),
onSuccess: () => {
// Invalidate and refetch
queryClient.invalidateQueries('todos')
queryClient.invalidateQueries({ queryKey: ['todos'] })
},
})

return (
<div>
<ul>
{query.data.map(todo => (
{query.data?.map((todo) => (
<li key={todo.id}>{todo.title}</li>
))}
</ul>
Expand Down
0