react-query#QueryClient TypeScript Examples

The following examples show how to use react-query#QueryClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApiClientContextController.tsx    From react-starter-boilerplate with MIT License 6 votes vote down vote up
ApiClientContextController = ({ children }: ApiClientControllerProps) => {
  const { queryFn, mutationFn, infiniteQueryFn } = useAxiosStrategy();
  /** example of usage of different strategy **/
  // const { queryFn, mutationFn, infiniteQueryFn } = useKyStrategy();

  const queryClient = useMemo(() => {
    return new QueryClient({
      defaultOptions: {
        queries: {
          queryFn: queryFn(),
        },
      },
    });
  }, [queryFn]);

  const ctxValue: ApiClientContextValue = useMemo(
    () => ({
      queryFn,
      mutationFn,
      infiniteQueryFn,
    }),
    [queryFn, mutationFn, infiniteQueryFn],
  );

  return (
    <ApiClientContext.Provider value={ctxValue}>
      <QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
    </ApiClientContext.Provider>
  );
}
Example #2
Source File: App.tsx    From homebase-app with MIT License 6 votes vote down vote up
queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 60000),
      retry: false,
      retryOnMount: false,
      refetchOnMount: false,
      refetchOnWindowFocus: true,
      staleTime: 5000,
      cacheTime: 30000,
    },
  },
})
Example #3
Source File: ShortcutLinks.spec.tsx    From apps with GNU Affero General Public License v3.0 6 votes vote down vote up
renderComponent = (bootData = defaultBootData): RenderResult => {
  const queryClient = new QueryClient();
  const app = 'extension';
  mocked(getBootData).mockResolvedValue(getBootMock(bootData));
  return render(
    <QueryClientProvider client={queryClient}>
      <BootDataProvider app={app} getRedirectUri={jest.fn()}>
        <ShortcutLinks />
      </BootDataProvider>
    </QueryClientProvider>,
  );
}
Example #4
Source File: App.tsx    From kubenav with MIT License 6 votes vote down vote up
queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      retry: false,
      refetchInterval: false,
      refetchIntervalInBackground: true,
      refetchOnWindowFocus: false,
      refetchOnReconnect: false,
    },
  },
})
Example #5
Source File: index.tsx    From Riakuto-StartingReact-ja3.1 with Apache License 2.0 6 votes vote down vote up
queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      retry: 0,
      suspense: true,
      // useErrorBoundary: true,
    },
    mutations: {
      retry: 0,
      // useErrorBoundary: true,
    },
  },
})
Example #6
Source File: recurringDonation.ts    From frontend with MIT License 6 votes vote down vote up
export async function prefetchRecurringDonationById(
  client: QueryClient,
  id: string,
  token?: string,
) {
  await client.prefetchQuery<RecurringDonationResponse>(
    endpoints.recurringDonation.getRecurringDonation(id).url,
    authQueryFnFactory<RecurringDonationResponse>(token),
  )
}
Example #7
Source File: updateGuest.ts    From rcvr-app with GNU Affero General Public License v3.0 6 votes vote down vote up
export async function updateCurrentGuest(
  queryClient: QueryClient,
  guest: db.Guest
): Promise<db.Checkin> {
  // First we update the current guest in local DB (if it exists)
  const currentGuest = await getCurrentGuest()
  if (currentGuest) {
    await updateGuest(guest)
  }
  // The we fetch and update the last checkin
  const currentCheckin = await getLastNonProxyCheckin()
  currentCheckin.guest = guest
  const updatedCheckin = await updateCheckin(currentCheckin)
  // We also need to update the data in the API (only if the public key is available (downwards compability))
  if (updatedCheckin.k) {
    const csv = toCSV(updatedCheckin.guest)
    const encryptedData = encrypt(updatedCheckin.k, csv)
    await api.patchTicket({
      id: updatedCheckin.id,
      encryptedData: encryptedData,
    })
  }
  // Finally we need to refresh the checkins in order to display it in my-checkins
  queryClient.invalidateQueries('checkins')
  return updatedCheckin
}
Example #8
Source File: index.tsx    From akashlytics with GNU General Public License v3.0 5 votes vote down vote up
queryClient = new QueryClient()
Example #9
Source File: QueryProvider.tsx    From anchor-web-app with Apache License 2.0 5 votes vote down vote up
queryClient = new QueryClient()
Example #10
Source File: App.tsx    From github-explorer with MIT License 5 votes vote down vote up
queryClient = new QueryClient()
Example #11
Source File: _app.tsx    From RareCamp with Apache License 2.0 5 votes vote down vote up
queryClient = new QueryClient()
Example #12
Source File: index.tsx    From rari-dApp with GNU Affero General Public License v3.0 5 votes vote down vote up
queryClient = new QueryClient()
Example #13
Source File: App.tsx    From kinopub.webos with MIT License 5 votes vote down vote up
queryClient = new QueryClient({
  defaultOptions: {
    queries: {
      staleTime: 5 * 60 * 1000,
    },
  },
})
Example #14
Source File: react-query.tsx    From react-query-auth with MIT License 5 votes vote down vote up
queryClient = new QueryClient()
Example #15
Source File: _app.tsx    From NextPay with MIT License 5 votes vote down vote up
queryClient = new QueryClient()
Example #16
Source File: _app.tsx    From frontend-boilerplate with MIT License 5 votes vote down vote up
queryClient = new QueryClient()
Example #17
Source File: HomePageCalendar.tsx    From backstage with Apache License 2.0 5 votes vote down vote up
queryClient = new QueryClient()
Example #18
Source File: _app.tsx    From basement-grotesque with SIL Open Font License 1.1 5 votes vote down vote up
queryClient = new QueryClient()
Example #19
Source File: App.tsx    From platform with MIT License 5 votes vote down vote up
queryClient = new QueryClient()
Example #20
Source File: Root.tsx    From crust-apps with Apache License 2.0 5 votes vote down vote up
function Root ({ store }: Props): React.ReactElement<Props> {
  const [theme, setTheme] = useState(() => createTheme(settings));
  const client = useRef(new QueryClient());

  useEffect((): void => {
    settings.on('change', (settings) => setTheme(createTheme(settings)));
  }, []);

  const args = getQueryStringArgs();

  if (args.elrondAddress) {
    let params = '?';

    Object.keys(args).forEach((e) => {
      params += e + '=' + args[e] + '&';
    });
    window.location.assign(`${window.location.origin}${window.location.pathname}${params}/#/bridge/elrondToCrust`);
    // window.location.reload();
  }

  return (
    <Suspense fallback='...'>
      <ThemeProvider theme={theme}>
        <Queue>
          <QueryClientProvider client={client.current}>
            <Api
              store={store}
              url={settings.apiUrl}
            >
              <BlockAuthors>
                <Events>
                  <HashRouter>
                    <WindowDimensions>
                      <Apps />
                    </WindowDimensions>
                  </HashRouter>
                </Events>
              </BlockAuthors>
            </Api>
          </QueryClientProvider>
        </Queue>
      </ThemeProvider>
    </Suspense>
  );
}
Example #21
Source File: App.tsx    From apps with GNU Affero General Public License v3.0 5 votes vote down vote up
queryClient = new QueryClient()