Socket
Book a DemoInstallSign in
Socket

react-query-useful-hooks

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-query-useful-hooks

The best and useful hooks for [react-query]

1.1.0
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

react-query-useful-hooks

The best and useful hooks for react-query

GitHub branch checks state GitHub issues GitHub npm Website GitHub language count GitHub top language GitHub code size in bytes

Features

  • All the [axios] awesomeness you are familiar with
  • Zero configuration, but configurable if needed
  • One-line usage

Installation

npm install axios react-query react-query-useful-hooks

axios and react-query is a peer dependency and needs to be installed explicitly

Quick Start

import React from 'react';
import {useFetch} from 'react-query-useful-hooks';

import React from 'react';
import {useFetch} from 'react-query-useful-hooks';

function Todos() {
    const {isError, isFetching, data, refetch} = useFetch({
        url: 'todos/1',
        enabled: true
    });

    if (isFetching) return <p>Loading...</p>;
    if (isError) return <p>Error!</p>;
    return (
        <div>
            <button onClick={() => refetch()}>refetch</button>
            <pre>{JSON.stringify(data, null, 2)}</pre>
        </div>
    );
}

export default Todos;

API

The package exports one default export and named exports:

import {
    useFetch,
    useInfinite,
    usePaginate,
    usePost,
    useModifyQuery,
    usePersist,
    useSubscribeQuery,
    configure
} from 'react-query-useful-hooks';

Configuration

Unless provided via the configure function, react-query-useful-hooks uses as defaults:

These defaults may not suit your needs, for example:

  • you may want a common base url or timeout for axios requests
  • need to customize cacheTime or staleTime
  • or different behavior in onSuccess and onError requests

In such cases you can use the configure function to provide your custom implementation of both.

When configure is used, it should be invoked once before any usages of hooks

Example

import { configure } from 'react-query-useful-hooks'
import axios from 'axios'

configure({
    axios: axios.create({
        baseURL: 'https://jsonplaceholder.typicode.com',
        timeout: 1000
    }),
    queryOptions: {
        retry: 5,
        retryDelay: 100,
        retryOnMount: false
    }
});

Creator

Sina Shah Oveisi @sinashahoveisi

I love programming, and I am interested in popular frameworks or programming languages and I am currently coding with JavaScript and React framework.

License

MIT © Sina Shahoveisi

Keywords

react

FAQs

Package last updated on 26 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.