# react-query-use-once

> A extension for react-query to prevent auto refetching of a query.

Latest version **2.0.1** (published 2022-08-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-query-use-once
pnpm add react-query-use-once
yarn add react-query-use-once
bun add react-query-use-once
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2022-08-24 |
| First published | 2021-10-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | Richard M Hpa |
| Maintainers | richardhpa |
| Keywords | npm, package, template |

## Links

- npm: https://www.npmjs.com/package/react-query-use-once
- Repository: https://github.com/RichardHpa/react-query-use-once
- Homepage: https://github.com/RichardHpa/react-query-use-once#readme
- Issues: https://github.com/RichardHpa/react-query-use-once/issues
- npm.io page: https://npm.io/package/react-query-use-once

## Dependencies (1)

- [commitizen](https://npm.io/package/commitizen.md) ^4.2.4

## Recent versions

- 2.0.1 (latest) — 2022-08-24
- 0.0.0-development — 2022-08-24
- 1.0.0 — 2021-10-05

## README

# React Query Use Once

[![RichardHpa - react-query-use-once](https://img.shields.io/static/v1?label=RichardHpa&message=react-query-use-once&color=blue&logo=github)](https://github.com/RichardHpa/react-query-use-once)
[![stars - react-query-use-once](https://img.shields.io/github/stars/RichardHpa/react-query-use-once?style=social)](https://github.com/RichardHpa/react-query-use-once)
[![forks - react-query-use-once](https://img.shields.io/github/forks/RichardHpa/react-query-use-once?style=social)](https://github.com/RichardHpa/react-query-use-once)

[![Node.js CI](https://github.com/RichardHpa/react-query-use-once/workflows/Node.js%20CI/badge.svg)](https://github.com/RichardHpa/react-query-use-once/actions?query=workflow:"Node.js+CI")
[![codecov coverage](https://img.shields.io/codecov/c/github/RichardHpa/react-query-use-once.svg?style=flat-square)](https://github.com/RichardHpa/react-query-use-once)
[![License](https://img.shields.io/badge/License-MIT-blue)](#license)

A extension for react-query to prevent auto refetching of a query.

## Background

In a few of my projects, I have ran into a scenario where I don't want a query to refetch by default. This hook includes the query params to prevent the auto refetching from happening. You can use all the usual react-query options and get the same values from the result.  
Even though the default refetching isn't happening you can still manually triggering a refetch via the query cache.

## Installation

Using npm:

```sh
$ npm install react-query-use-once
```

## Example

```javascript
import { useQueryOnce } from 'react-query-use-once';
import { QueryClient, QueryClientProvider } from 'react-query';

const queryClient = new QueryClient();

export default function App() {
  return (
    <QueryClientProvider client={queryClient}>
      <Example />
    </QueryClientProvider>
  );
}

function Example() {
  // Retrieve information about Luke Skywalker from Star Wars
  const { isLoading, error, data } = useQueryOnce('repoData', () =>
    fetch('https://swapi.dev/api/people/1/').then(res => res.json())
  );

  if (isLoading) return 'Loading...';

  return (
    <div>
      <h1>{data.name}</h1>
      <p>{data.birth_year}</p>
      <p>{data.gender}</p>
    </div>
  );
}
```

## React Query Docs

Visit [react-query.tanstack.com](https://react-query.tanstack.com) for docs, guides, API and more

## License

[react-query](https://github.com/tannerlinsley/react-query) is created by [Tanner Linsley](https://tannerlinsley.com/)

---
_Source: https://npm.io/package/react-query-use-once · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
