reactjs 错误:未设置QueryClient,请使用QueryClientProvider设置一个,我是否已设置QueryClient?

qvsjd97n  于 2023-01-17  发布在  React
关注(0)|答案(1)|浏览(82)

我已经将<ReactQueryDevtools />打包到<QueryClientProvider>中,所以我不明白为什么会遇到这个问题?
我已经看过TanStack Query文档,我不明白这个问题。

import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import { BrowserRouter } from 'react-router-dom';
import { worker } from '@uidotdev/react-query-api';
import { QueryClient, QueryClientProvider } from 'react-query';
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';

const queryClient = new QueryClient();

new Promise((res) => setTimeout(res, 100))
  .then(() =>
    worker.start({
      quiet: true,
      onUnhandledRequest: 'bypass',
    })
  )
  .then(() => {
    ReactDOM.render(
      <React.StrictMode>
        <QueryClientProvider client={queryClient}>
          <BrowserRouter>
            <div className="container">
              <App />
            </div>
          </BrowserRouter>
          <ReactQueryDevtools />
        </QueryClientProvider>
      </React.StrictMode>,
      document.getElementById('root')
    );
  });

我的主机:

Error: No QueryClient set, use QueryClientProvider to set one
g6ll5ycj

g6ll5ycj1#

其中一个导入不正确

import { QueryClient, QueryClientProvider } from 'react-query';

应该是

import { QueryClient, QueryClientProvider } from '@tanstack/react-query';

相关问题