Shipnative uses Zustand for local/global state and React Query for server data. This separation keeps your code clean and performant.Documentation Index
Fetch the complete documentation index at: https://docs.shipnative.app/llms.txt
Use this file to discover all available pages before exploring further.
Zustand: Global Client-Side State
Zustand is a small, fast, and scalable bear-bones state-management solution. It’s ideal for managing UI state, user preferences, and any other client-side data that doesn’t require server interaction.Key Features
- Simple API: Easy to learn and use, with a minimal boilerplate.
- Hooks-based: Integrates seamlessly with React’s functional components.
- Performant: Renders components only when necessary, optimizing performance.
- Scalable: Suitable for small to large applications.
Usage Pattern
- Define Your Store: Create a store using
createfromzustand. - Use in Components: Access state and actions using the custom hook.
Best Practices with Zustand
- Atomic Stores: Create small, focused stores for specific pieces of state.
- Selectors: Use selectors to extract only the necessary parts of the state, preventing unnecessary re-renders.
- Immutability: Always update state immutably (e.g., using spread syntax).
React Query: Server-Side State & Data Fetching
React Query (also known as TanStack Query) is a powerful library for managing, caching, synchronizing, and updating server state in your React Native applications. It handles the complexities of data fetching, leaving you with more time to focus on your UI.Key Features
- Automatic Caching: Caches fetched data, reducing redundant network requests.
- Background Refetching: Automatically refetches stale data in the background.
- Optimistic Updates: Provides a smooth user experience by updating the UI before the server responds.
- Error Handling: Built-in mechanisms for handling and retrying failed requests.
- Pagination & Infinite Scrolling: Simplifies complex data fetching patterns.
Usage Pattern
- Define Your Query Function: A simple async function that fetches data.
- Use in Components with
useQueryoruseMutation:
Best Practices with React Query
- Query Keys: Use descriptive and consistent query keys for effective caching and invalidation.
- Query Invalidation: Invalidate queries after mutations to ensure your UI reflects the latest server state.
- Optimistic Updates: Implement optimistic updates for a snappier user experience, especially for actions like “liking” a post.
- Error Boundaries: Use React Error Boundaries to gracefully handle data fetching errors.
Combining Zustand and React Query
Zustand and React Query complement each other perfectly:- Zustand: Manages transient UI state (e.g., modal open/close, form input values before submission).
- React Query: Manages persistent server data (e.g., lists of items, user profiles fetched from an API, authentication status from a backend).
Storage: MMKV vs Supabase
Shipnative includes MMKV for fast local storage, but it’s important to understand when to use it vs Supabase.The Golden Rule
Supabase is for user data. MMKV is for local caching.When to Use Supabase
| Data Type | Example | Why Supabase |
|---|---|---|
| User profiles | Name, avatar, bio | Syncs across devices |
| User preferences | Theme, notifications | Available on any device |
| User content | Posts, messages, notes | Needs backup, sharing |
| Relationships | Friends, followers | Relational data with RLS |
When to Use MMKV
| Data Type | Example | Why MMKV |
|---|---|---|
| UI cache | Last subscription status | Fast loading before server responds |
| Local-only state | Last opened tab | Device-specific |
| Draft content | Unsaved form data | Temporary until user saves |
Example: User Preferences
What Shipnative Uses MMKV For
The boilerplate uses MMKV sparingly for caching:- Subscription status cache - RevenueCat is the source of truth; MMKV provides instant UI feedback
- Onboarding progress cache - Supabase
profilesis the source of truth; MMKV speeds up the UI
Resources
- Zustand Documentation: https://zustand-demo.pmnd.rs/
- React Query Documentation: https://tanstack.com/query/latest
- Shipnative Stores:
apps/app/app/stores/(for Zustand examples) - Shipnative Services:
apps/app/app/services/(for data fetching examples with React Query)

