react-query-render-state
TypeScript icon, indicating that this package has built-in type declarations

1.0.16 • Public • Published

React Query Render State

All Contributors NPM License NPM Downloads

React Query Render State: This hook allows you to declaratively define components that will be rendered based on the data processing state.

Installation

The easiest way to install react-query-render-state is with npm.

npm install react-query-render-state

Alternately, download the source.

git clone https://github.com/stegano/react-query-render-state.git

Quick Start

The useQueryRenderState hook enables a declarative approach to display components based on data processing status.

import { useQueryRenderState } from "react-query-render-state";

export const App = () => {
  const { render, ...queryResult } = useQueryRenderState({
    // ...`useQuery` options
    // You can also use `useInfiniteQueryRenderState` in the same way.
  });

  return render(
    () => <p>Idle</p>,                             // → renderIdle
    () => <p>Loading..</p>,                        // → renderLoading
    (data) => <div>Success({data})</div>,          // → renderSuccess
    (error) => <p>Error. :(, ({error.message})</p> // → renderError
  );
};

Demo: https://stackblitz.com/edit/stackblitz-starters-ccrgxa9c

Note: ✨ react-query-render-state is made based on @tanstack/react-query and react-render-state

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Yongwoo Jung
Yongwoo Jung

💻 🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

/react-query-render-state/

    Package Sidebar

    Install

    npm i react-query-render-state

    Weekly Downloads

    74

    Version

    1.0.16

    License

    MIT

    Unpacked Size

    18.2 kB

    Total Files

    19

    Last publish

    Collaborators

    • stegano