-
-
Notifications
You must be signed in to change notification settings - Fork 29
(Server) State query clients
LeoTM edited this page Jul 24, 2022
·
2 revisions
React + Promise/REST/GraphQL
- fetcher
- pagination
loading: boolean
- onError
(error: Error) => { // handle }
- onSuccess
(data<T>): T[] => { // render data }
- live/offline caching, garbage collection
- retrying
- polling
- API style declarative/on-use
- React Suspense
interface Product {
// ...
}
const getProducts = async () => {
const res = await fetch('http://localhost:1337/products')
const json: Product[] = await res.json()
return json
}
const [products, setProducts] = useState<Product[]>([])
useEffect(() => {
const doEffect = async () => {
setProducts(await getProducts())
}
doEffect()
}, [])
https://swr.vercel.app/docs/advanced/react-native
// SWRConfig global context broken with React Native
const SwrApp = (
<SWRConfig>
<App />
</SWRConfig>
)
// But useSWR fine with React Native
const { data, error } = useSWR('app_products', getProducts)
Add React Native + React Navigation compatibility: @nandorojo/swr-react-native
Redux + Promise/REST/GraphQL