I'd say use swr (swr.vercel.app/) when calling APIs, it returns the data, error, and if it's loading (plus cache, deduplication, etc). Here's a snippet from their website:
import useSWR from 'swr'
function Profile() {
const { data, error } = useSWR('/api/user', fetcher)
if (error) return <div>failed to load</div>
if (!data) return <div>loading...</div>
return <div>hello {data.name}!</div>
}
Hi 👋, I’m a React Native freelance engineer working remotely.
I am on a mission is to make people’s lives easier through mentoring, minimalist design, and automation.
Tanner Linsley (author of React Query) details the differences here (also comparing Apollo and RTK Query) much better than I can: react-query.tanstack.com/comparison
I'd say use swr (swr.vercel.app/) when calling APIs, it returns the data, error, and if it's loading (plus cache, deduplication, etc). Here's a snippet from their website:
Or React Query. But yes, separate server fetching from local state.
This! No need to reinvent the wheel every time you want an API dependent state variable
@stereoplegic
Do you know what are the differences between
swr
andreact-query
?I use both and I have no idea how to pitch the differences 😆
Tanner Linsley (author of React Query) details the differences here (also comparing Apollo and RTK Query) much better than I can: react-query.tanstack.com/comparison
I have used react query and it is quite good. I didn't know about swr though. Will check this out. Thanks for sharing
I fully agree. Don't reinvent the wheel. There's also URQL if you're dealing with GraphQL
formidable.com/open-source/urql/do...