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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@umituz/react-native-tanstack

v1.2.5

Published

TanStack Query configuration and utilities for React Native apps - Pre-configured QueryClient with AsyncStorage persistence

Downloads

614

Readme

@umituz/react-native-tanstack

TanStack Query configuration and utilities for React Native apps with AsyncStorage persistence.

Features

  • Pre-configured QueryClient - Sensible defaults out of the box
  • AsyncStorage Persistence - Automatic cache restoration on app restart
  • Cache Strategies - Pre-defined strategies for different data types
  • Query Key Factories - Type-safe key generation patterns
  • Pagination Helpers - Cursor and offset-based pagination
  • Optimistic Updates - Easy optimistic UI with automatic rollback
  • Dev Tools - Built-in logging for development
  • General Purpose - Works with Firebase, REST, GraphQL, any async data source

Installation

npm install @umituz/react-native-tanstack

Peer Dependencies

npm install @tanstack/react-query @react-native-async-storage/async-storage

Usage

Basic Setup

import { TanstackProvider } from '@umituz/react-native-tanstack';

function App() {
  return (
    <TanstackProvider>
      <YourApp />
    </TanstackProvider>
  );
}

Custom Configuration

import { TanstackProvider, TIME_MS } from '@umituz/react-native-tanstack';

function App() {
  return (
    <TanstackProvider
      queryClientOptions={{
        defaultStaleTime: 10 * TIME_MS.MINUTE,
        enableDevLogging: __DEV__,
      }}
      persisterOptions={{
        keyPrefix: 'myapp',
        maxAge: 24 * TIME_MS.HOUR,
        busterVersion: '1',
      }}
      onPersistSuccess={() => console.log('Cache restored!')}
    >
      <YourApp />
    </TanstackProvider>
  );
}

Cache Strategies

import { useQuery, CacheStrategies } from '@umituz/react-native-tanstack';

// Real-time data (always refetch)
const { data: liveScore } = useQuery({
  queryKey: ['score'],
  queryFn: fetchScore,
  ...CacheStrategies.REALTIME,
});

// User data (medium cache)
const { data: profile } = useQuery({
  queryKey: ['profile'],
  queryFn: fetchProfile,
  ...CacheStrategies.USER_DATA,
});

// Master data (long cache)
const { data: countries } = useQuery({
  queryKey: ['countries'],
  queryFn: fetchCountries,
  ...CacheStrategies.MASTER_DATA,
});

// Public data (medium-long cache)
const { data: posts } = useQuery({
  queryKey: ['posts'],
  queryFn: fetchPosts,
  ...CacheStrategies.PUBLIC_DATA,
});

Query Key Factories

import { createQueryKeyFactory } from '@umituz/react-native-tanstack';

const postKeys = createQueryKeyFactory('posts');

// All posts
postKeys.all(); // ['posts']

// Posts list
postKeys.lists(); // ['posts', 'list']

// Posts with filters
postKeys.list({ status: 'published' }); // ['posts', 'list', { status: 'published' }]

// Single post
postKeys.detail(123); // ['posts', 'detail', 123]

// Custom key
postKeys.custom('trending'); // ['posts', 'trending']

Pagination

import { useCursorPagination } from '@umituz/react-native-tanstack';

function FeedScreen() {
  const { data, flatData, fetchNextPage, hasNextPage, isFetchingNextPage } = useCursorPagination({
    queryKey: ['feed'],
    queryFn: ({ pageParam }) => fetchFeed({ cursor: pageParam, limit: 20 }),
    limit: 20,
  });

  return (
    <FlatList
      data={flatData}
      onEndReached={() => hasNextPage && fetchNextPage()}
      onEndReachedThreshold={0.5}
    />
  );
}

Cache Invalidation

import { useInvalidateQueries } from '@umituz/react-native-tanstack';

function ShareButton() {
  const invalidate = useInvalidateQueries();

  const handleShare = async () => {
    await shareToFeed(post);

    // Invalidate feed queries
    await invalidate(['feed']);
  };

  return <Button onPress={handleShare}>Share</Button>;
}

Optimistic Updates

import { useOptimisticUpdate } from '@umituz/react-native-tanstack';

function LikeButton({ postId }) {
  const updateLike = useOptimisticUpdate<Post, { liked: boolean }>({
    mutationFn: (variables) => api.updatePost(postId, variables),
    queryKey: ['posts', 'detail', postId],
    updater: (oldPost, variables) => ({
      ...oldPost,
      liked: variables.liked,
      likeCount: oldPost.likeCount + (variables.liked ? 1 : -1),
    }),
  });

  const handleLike = () => {
    updateLike.mutate({ liked: true });
  };

  return <Button onPress={handleLike}>Like</Button>;
}

Cache Strategies

| Strategy | staleTime | gcTime | Use Case | |----------|-----------|--------|----------| | REALTIME | 0 | 5 min | Live data (chat, scores) | | USER_DATA | 30 min | 24 hours | User profile, settings | | MASTER_DATA | 24 hours | 7 days | Countries, categories | | PUBLIC_DATA | 30 min | 24 hours | Feed, blog posts |

API Reference

See TypeScript definitions for complete API documentation.

License

MIT © Ümit UZ