npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

remote-data-react-query

v1.2.1

Published

ADT for react-query

Downloads

18

Readme

ADT compatible with useQuery from '@tanstack/react-query'

Prerequisites:

  • Basic knowledge of FP approach
  • UseQuery hook from react-query

Prior art:

Installation

yarn add remote-data-react-query

Lite version

There are 3 versions of this package, first one is BASED on fp-ts. Use this version if you already use fp-ts in your project

import { remote, RemoteData } from 'react-query-remote-data';

More expected, you don't use fp-ts yet, in that case import lite version without fp-ts peer dependency

import { remote, RemoteData } from 'react-query-remote-data/lite';

And a lite version for react-query@3

import { remote, RemoteData } from 'react-query-remote-data/v3lite';

Guide

Check out examples in this repo at src/dev/stories for comparison with classic approach.

Usage example

import React from 'react';
import { useQuery } from '@tanstack/react-query';
import { remote, RemoteData, RenderRemote } from 'remote-data-react-query/lite';

type User = { name: string; phone: string };

export const UsageExample = () => {
    const user: RemoteData<Error, User> = useQuery(['user'], () =>
        fetch(`https://jsonplaceholder.typicode.com/users/1`).then(res => res.json()),
    );

    const userPhone = remote.pipe(
        user,
        remote.map((user) => user.phone),
    );

    return (
        <RenderRemote
            data={userPhone}
            success={(phone) => <div>{phone}</div>}
            refetching={(phone) => <div>{phone} refreshing...</div>}
            failure={(e) => <div>failed to fetch {e.message}</div>}
            pending={<div>just pending</div>}
            initial={<div>initial</div>}
        />
    );
};

Lite API

Lite API for react-query@3

Normal API

CHANGELOG

0.0.1 06.08.2022

  • Initial release

0.0.2 07.08.2022

  • Updated readme

1.0.0 30.08.2022

  • Removed RQ suffix
  • Removed useless generics (i.e. getOrElse<E, A> -> getOrElse<A>)
  • Renamed sequenceS -> combine
  • Renamed sequenceT -> sequence
  • Fixed fp-ts peer import
  • Added mapLeft

1.1.0 14.10.2022

  • Added remove and refetch methods to RemoteData
  • Added lite version (if you don't use fp-ts)

1.2.0 16.10.2022

  • Added lite version react-query@3

1.2.1 17.10.2022

  • Added UseQueryResult as generic for better type inference
  • Added more overloads for Pipe and Sequence