@cochoio/react-query-component
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

react-query-component

This is a library created to use react-query as a component.

Install

$ yarn add @cochoio/react-query-component
// npm install @cochoio/react-query-component

Example

type MockData = {
  id: number;
  name: string;
};

function TestingComponent() {

    return (
        <Query<MockData>
            queryKey={["api-key"]}
            queryFn={async () => {
                return {
                    id: 1,
                    name: "test",
                }
            }}
        >
            {({ data, isFetching }) => {
                if (!data && isFetching) {
                    return <p>Loading...</p>;
                }

                if (!data) {
                    return <div>Data Is Not Found</div>;
                }

                return (
                    <div>
                        {data.id} {data.name}
                    </div>
                );
            }}
        </Query>
    );
}

Package Sidebar

Install

npm i @cochoio/react-query-component

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

8.19 kB

Total Files

10

Last publish

Collaborators

  • cochoio