Code Monkey home page Code Monkey logo

react-query-suspense's Introduction

Factory emoji

React Query Suspense

Latest build Latest published version Bundlephobia Tree shaking available Types included License Number of downloads GitHub Stars


another way to suspense the @tanstack/query calls by queryKeys with multiples possibilities.
Suspense your component wherever you want just passing a query key call.


๐Ÿ“ฆ Install

React Query Suspense is available as a package on NPM, install with your favorite package manager:

npm install @kappys/react-query-suspense

โšก Quick start

start wrapping the content that you want suspense until the call is ready to render.

Simple way wrapping a component with ReactQuerySuspense waiting the example query key call.

Is not necessary pass isLoading or isSuccess, just pass the queryKey and forget all things.

import React from "react";
import { ReactQuerySuspense, QueryKey } from '@kappys/react-query-suspense'

export const SampleComponent: React.FC<React.PropsWithChildren<{
  keys: QueryKey[];
}>> = ({ children, keys }) => {

  const key: QueryKey = ["example"];

  return (
    <ReactQuerySuspense Fallback={<>loading</>} queryKeys={keys}>
      <div>{children}</div>
    </ReactQuerySuspense>
  );
};

Example with ReactQuerySuspense in real world waiting multiples calls

Edit react-query-suspense

๐Ÿ“ Features

Important: On Error fetch, this library will keep loading, in a future we will implement FallbackError

Suspense

<ReactQuerySuspense Fallback={<>loading</>} queryKeys={['query', 'key']}>
  <div>Test</div>
</ReactQuerySuspense>

Suspense with deferred fetch option

  • it will force to put the loading in the first rendering.
<ReactQuerySuspense Fallback={<>loading</>} queryKeys={['query', 'key']} deferredFetch>
  <div>Test</div>
</ReactQuerySuspense>

Suspense waiting multiples calls

const keys1 = ['query', 'key1'];
const keys2 = ['query', 'key2'];

<ReactQuerySuspense Fallback={<>loading</>} queryKeys={[[keys1], [keys2]]}>
  <div>Test</div>
</ReactQuerySuspense>

Hook to know if the call is fetching or not.

const suspense: boolean = useReactQuerySuspense({ queryKeys })

๐Ÿ“˜ API Reference

ReactQuerySuspense

Attributes

  • Fallback: React.ReactNode
    • Required
  • queryKeys: QueryKey[]
    • Required
    • QueryKey that you are using to identify your calls in useQuery and useMutation
  • context?: QueryClient
    • Optional
    • Possibility to pass another context to listen, the context is provided when you call new QueryClient
  • deferredFetch?: boolean
    • Optional
    • it provides you the possibility to render the Fallback first.

useReactQuerySuspense

Options

  • queryKeys: QueryKey[]
    • Required
    • QueryKey that you are using to identify your calls in useQuery and useMutation
  • context?: QueryClient
    • Optional
    • Possibility to pass another context to listen, the context is provided when you call new QueryClient
  • deferredFetch?: boolean
    • Optional
    • It provides you the possibility to render the Fallback first.

Return

  • suspense: boolean
    • Return a boolean with the status of suspense.

Issues

Looking to contribute? Look for the [Good First Issue][good-first-issue] label.

๐Ÿ› Bugs

Please file an issue for bugs, missing documentation, or unexpected behavior.

[See Bugs][bugs]

๐Ÿ’ก Feature Requests

Please file an issue to suggest new features. Vote on feature requests by adding a ๐Ÿ‘. This helps maintainers prioritize what to work on.

[See Feature Requests][requests]

LICENSE

MIT

react-query-suspense's People

Contributors

kappys1 avatar

Watchers

 avatar

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.