rn-data-fetching
/rn-data-fetching
Prowadzi przez pobieranie danych z API w React Native z TanStack Query: zapytania, mutacje, aktualizacje optymistyczne, listy z paginacją, unieważnianie cache i obsługę stanów ładowania.
- Autor
- lukedj78 ↗
- Repozytorium
- dev-flow ↗
- Licencja
- MIT
- Ostatnia zmiana repozytorium
- 22.10.2026
Ocena i bezpieczeństwo
- Pliki w paczce
- 9
- Skrypty
- 3
- Komentarze HTML
- 0
- Adresy URL w SKILL.md
- 3
Brak sygnałów. Repozytorium zmienione 22.10.2026, bez odwołań do wycofanych modeli i API.
MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.
- 3 skrypty w paczce. Przejrzyj je przed instalacją, bo Claude może je uruchomić.
Skrypty: references/examples/infinite-scroll.tsx, references/examples/mutation-optimistic.tsx, references/examples/query-basic.tsx
Co robi i kiedy
Prowadzi przez pobieranie danych z API w React Native z TanStack Query: zapytania, mutacje, aktualizacje optymistyczne, listy z paginacją, unieważnianie cache i obsługę stanów ładowania.
Wyzwalacze z opisu
Oryginalny opis (EN)
Use when fetching data from APIs in React Native: choosing between fetch+useEffect (didactic only) and TanStack Query (production default), wiring the QueryClient provider, building queries / mutations / optimistic updates / paginated and infinite lists / cache invalidation / refetch on focus, handling loading and error states, AsyncStorage persistence, offline-first behavior. Triggers on: "fetch posts from API", "infinite scroll", "optimistic mutation", "cache invalidation", "loading state". Not for: styling lists (rn-styling), backend setup (rn-backend, Wave 3 — provider-agnostic), GraphQL c
Jak działa
- The 5 rules (non-negotiable)
- Quick decision tree
- Common anti-patterns (NEVER do)
- Sources
Podgląd SKILL.md
---
name: rn-data-fetching
description: 'Use when fetching data from APIs in React Native: choosing between fetch+useEffect (didactic only) and TanStack Query (production default), wiring the QueryClient provider, building queries / mutations / optimistic updates / paginated and infinite lists / cache invalidation / refetch on focus, handling loading and error states, AsyncStorage persistence, offline-first behavior. Triggers on: "fetch posts from API", "infinite scroll", "optimistic mutation", "cache invalidation", "loading state". Not for: styling lists (rn-styling), backend setup (rn-backend, Wave 3 — provider-agnostic), GraphQL clients (out of scope).'
---
# rn-data-fetching — guardrail for data fetching in React Native + Expo
> For the current Expo API and per-version details, verify against the Expo docs / MCP `mcp.expo.dev` / `expo/skills` (see rn-fundamentals → Source of truth).
## The 5 rules (non-negotiable)
1. **TanStack Query is the default** for any data that comes from the network. `fetch + useEffect` is acceptable ONLY in didactic examples or for one-off bootstrap calls (e.g. reading a config at app start).
2. **One `QueryClient` per app, mounted at the root layout.** Never instantiate per-screen.
3. **Query keys are arrays**, hierarchical, with the most specific filter last: `["posts", "list", { filter }]`. NEVER stringly-typed keys.
4. **Every mutation invalidates the queries it affects**. Use `queryClient.invalidateQueries({ queryKey: [...] })` in `onSuccess`. Optimistic updates use `onMutate` + `onError` rollback.
5. **`staleTime` ≥ 60_000 ms is the default** to avoid refetch-on-focus storms. Tune per query based on freshness need.
## Quick decision tree
- "Should I use fetch or TanStack Query?" → `references/decision-tree.md`
- "How do I set up TanStack Query in a fresh Expo app?" → `references/tanstack-query-rn.md`
- "What's the right query key shape, the right cancel pattern, the right loading state?" → `references/patterns.md`
- "Show me a working query / mutation / infinite scroll example" → `references/examples/`
- "Why does my fetch race on unmount?" → `references/concepts.md`
## Common anti-patterns (NEVER do)
- ❌ `useEffect(() => { fetch(...).then(setData) }, [])` for production data — no retry, no dedup, no cancel.
- ❌ `useState<Data | null>(null)` + `useState<boolean>(false)` for loading — let TanStack Query own server state.
- ❌ `queryKey: "posts"` as a string — must be an array.
- ❌ Calling `setData` after the component unmounts — TanStack Query handles cancel automatically.
- ❌ Mutation that updates the server but does NOT `invalidateQueries` — UI shows stale data.
- ❌ Refetching on every navigation — set `staleTime` per query.
## Sources
- Course: codewithbeto.dev/rnCourse — lesson 7 "Fetching Data from an API" + lesson 8 "Rendering Lists and TypeScript" (free).
- Official: https://tanstack.com/query/v5/docs/framework/react/overview
- Official: https://tanstack.com/query/v5/docs/framework/react/guides/mutations
- Official: https://docs.expo.dev/develop/development-builds/use-development-builds/
Pliki w paczce (9)
- SKILL.md 3 KB
- references/concepts.md 5 KB
- references/decision-tree.md 3 KB
- references/patterns.md 5 KB
- references/tanstack-query-rn.md 11 KB
- references/examples/.gitkeep 1 KB
- references/examples/infinite-scroll.tsx 2 KB
- references/examples/mutation-optimistic.tsx 3 KB
- references/examples/query-basic.tsx 2 KB
Wersje
W bazie nie ma innych skilli o nazwie rn-data-fetching.
Migawka bazy z 28.10.2026 · wersja paczki 753e5e3b3c39 (skrót SHA-256 całej paczki)
Pobrania w ostatnich 30 dniach: 0 · ranking
Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.
Podobne skille
- 100tanstack-react-query-patterns
Pomaga pisać typowane hooki do danych w React Query: fabryki kluczy, konfigurację QueryClient, unieważnianie cache i aktualizacje optymistyczne. - 90TanStack Query
Doradza w TanStack Query (React Query): zapytania, mutacje, cache, unieważnianie, aktualizacje optymistyczne, paginacja i zapytania nieskończone przy zarządzaniu stanem serwera w React. - 100tanstack-query
Obsługuje TanStack Query do pobierania danych w React: zapytania, mutacje, cache, infinite scroll, optymistyczne aktualizacje, prefetching i stan serwerowy. - 90frontend-data-fetching
Projektuje warstwę pobierania danych we frontendzie: stan serwera, cache, aktualizacje optymistyczne, paginację i nieskończone przewijanie. - 100tanstack-query
Zastępuje ręczne pobieranie danych przez useEffect i useState cache'owaniem danych serwerowych w React: refetch w tle, mutacje z optimistic updates, infinite scroll i Suspense (hooki v5). - 100tanstack-query
Podaje dobre praktyki TanStack Query v5 dla stanu serwerowego: fabryki kluczy zapytań, queryOptions, mutacje, optymistyczne aktualizacje, infinite queries, tryb Suspense i migracja z v4.