Giter VIP home page Giter VIP logo

react-query-web-i18n's People

Contributors

cangsdarm avatar donniean avatar emily-0616 avatar youky1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

react-query-web-i18n's Issues

为什么会有那么怪异的行为~~

dependencies:

 "react": "^18.0.0",
    "react-dom": "^18.0.0",
    "react-query": "^3.39.2",

code:

import axios from "axios";
import React from 'react';
import { createRoot } from 'react-dom/client';
import { QueryClient, QueryClientProvider, useQuery } from 'react-query';
const queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      refetchOnWindowFocus: false
    }
  }
})

function Layout() {
  const { isLoading, isError, error, data } = useQuery(["fff", { aa: 111 }], (param) => {
  //  let tmp = param.signal;//访问了 signal就会执行2次 不访问就执行一次 
    return axios.get("http://www.httpbin.org/get");
  })
  if (isLoading) {
    return <div>loading</div>
  }
  if (isError) {
    return <div>{error.message}</div>
  }
  return <div>
    <div>data:{data ? data.data ? data.data.origin : "" : ""}</div>
  </div>
}


function Root() {
  return <>
    <QueryClientProvider client={queryClient}>
      <Layout />
    </QueryClientProvider>
  </>
}

const container = document.getElementById('root');
const root = createRoot(container);
root.render(<React.StrictMode><Root /></React.StrictMode>);

There is a delay in persisting storage using '@tanstack/query-sync-storage-persister' plug-ins.

Steps:
1. Invoke the login interface and use 'queryClient.setQueryData' to store the token.
2. Jump to the home page and invoke a new interface.
3. The local storage cannot be retrieved in axios' request interception.
Test:
I try not to use plugins and manually store them locally, when the login succeeds, the token is stored, and the new interface is invoked on the jump home page, the locally stored token can be obtained in axios request interception.
Code:
// login.tsx
const queryClient = useQueryClient()
const userData = useQuery({ queryKey: ['userData'], enabled: false })

const loginMutaion = useMutation(
	(params: FormState) =>
		loginService(...omit params),
	{
		onSuccess: async (res) => {
			if (res.code === '200') {
				queryClient.setQueryData(['userData'], res.data)
				message.success('登录成功')
				navigate('/common/Home')
			}
		}
	}
)

login => loginMutaion.mutate

// App.tsx
import { QueryClient } from '@tanstack/react-query'
import { PersistQueryClientProvider } from '@tanstack/react-query-persist-client'
import { createSyncStoragePersister } from '@tanstack/query-sync-storage-persister'

const queryClient = new QueryClient({
defaultOptions: {
	queries: {
		cacheTime: 1000 * 60 * 60 * 24 // 24 hours
		}
	}
})

const persister = createSyncStoragePersister({
	storage: window.localStorage,
	key: 'userData'
})

<PersistQueryClientProvider client={queryClient} persistOptions={{ persister }}>
	<Suspense>
		<Router />
	</Suspense>
</PersistQueryClientProvider>

status 通常表示终态,用state可能会有误解

位置:查询 Queries

为什么有两种表示状态的东西(status/fetchStatus)?

  • 一个state='success'的查询通常处于fetchStatus='idle'状态。但如果同时有后台重新获取动作,它也可能为fetchStatus='fetching'状态。 (这里的state,应该是status)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.