🆙 Update React Query to TanStack Query (#1153)

This commit is contained in:
Patrick Arminio
2024-04-04 16:30:42 +02:00
committed by GitHub
parent 3628e039f8
commit 2314dbd2df
19 changed files with 225 additions and 517 deletions

View File

@@ -1,6 +1,6 @@
import { useNavigate } from "@tanstack/react-router"
import { useState } from "react"
import { useMutation, useQuery } from "react-query"
import { useMutation, useQuery } from "@tanstack/react-query"
import {
type Body_login_login_access_token as AccessToken,
@@ -17,13 +17,11 @@ const isLoggedIn = () => {
const useAuth = () => {
const [error, setError] = useState<string | null>(null)
const navigate = useNavigate()
const { data: user, isLoading } = useQuery<UserOut | null, Error>(
"currentUser",
UsersService.readUserMe,
{
enabled: isLoggedIn(),
},
)
const { data: user, isLoading } = useQuery<UserOut | null, Error>({
queryKey: ["currentUser"],
queryFn: UsersService.readUserMe,
enabled: isLoggedIn(),
})
const login = async (data: AccessToken) => {
const response = await LoginService.loginAccessToken({
@@ -32,7 +30,8 @@ const useAuth = () => {
localStorage.setItem("access_token", response.access_token)
}
const loginMutation = useMutation(login, {
const loginMutation = useMutation({
mutationFn: login,
onSuccess: () => {
navigate({ to: "/" })
},