React Query is Secretly an Amazing State Manager

preview_player
Показать описание
It just works, no other state management library needed at all. That is pretty dope.

-- my links
Рекомендации по теме
Комментарии
Автор

well, zustand is more of a client state library where react query is more of a server state library. I think they have different main purposes.

gioelem
Автор

you actually don't need to return the refetch function, you could also invalidate the query cache key "cart", because that is in use it would get refetched directly

balduin_b
Автор

I find react query also REALLY shines when it comes to optimistic updating.
When combined with tRPC so you don’t have to even worry about type casting or passing around query keys and such, it’s crazy how simple all this is made.

Fuzbo_
Автор

Something to point out is that this approach is more suited toward server-state.
Zustand, Redux, XState and other state-machine like solutions do still hold a strong place. Especially is you have client-side data that you need to manage/cannot store on a server. Think more along the lines of a predictable stream of storing state for a client app, stuff like an app local-shopping cart, theme, routing specific contextual info, etc.

That being said, not many web apps truly need a full fledged solution like Zustand or other, and can get by with React Context alone for most things. These state-machine like solutions start mattering more as your app grows and stuff like Redux slices or Zustand stores come into play where ownership of the store doesn't leak or cause side effects into others, WITHOUT having to have a 15 layer tree of context providers.

SeanCassiere
Автор

Is bro getting dumber or am I gaining some skills ?

Zustand and RQ are solutions for totally different problems. I use RQ to persist server side data and a global state manager like zustand to only keep client side state.

At the beginning of the video I thought he's gonna talk about great features of RQ like caching, smart fetching, mutations and all, but nope, bro violated us

azeek
Автор

Great content man, you are also the only person on the internet who pronounces zustand properly. I know the reason, I see your windows task bar.

snsa_kscc
Автор

For client side state management I'll take zustand any day of the week. I would only use react-query if I am dealing with server side state and not using trpc for some reason.

royz_
Автор

Why mention that you have to explicitly type the Zustand solution and not mention that you do the same with React Query with `return cart as Cart`? That's quite unfair.

alexandrepereira
Автор

You just showed basics of React Query? Dunno how you could not know about this

лилпипка
Автор

It's worth mentioning that this only works if you don't need to mutate the state on the client side. React Query is not a full on state manager, it just caches requests.

airixxxx
Автор

Why don’t people use RTK? It auto generates hooks for you that you can use anywhere. No need to write multiple fetch logic. I don’t get why people love react query so much over RTK.

OryginTech
Автор

I think everyone would love content on hydration and using react query and server components with nextjs. And all the great abstractions that would make it scalable.

noahginsburg
Автор

You don't really explain anything in this video...

talkohavy
Автор

I would just use trpc, it wrap react query and provide typesafety between your frontend and backend.

anonanon
Автор

i had no idea oranges are the better apples

bopatzable
Автор

what is the thing you didn't know React query can do?

filipkovac
Автор

Legend State with Tanstack Query seems like the way to go right now when it comes to state management in React imo.

wezter
Автор

Sorry Josh, didn't enjoy the video. The example you said was 'cleaner' didn't look cleaner to me. I'm really struggling to understand why and in what circumstances React Query is a good idea and this didn't help.

michaeldausmann
Автор

When I hear "state managers", I expect traditional state/settings/logic management.
This is "server cache management", which is a subset. State managers can become cache managers, but cache managers isn't suited to be come state managers since it's a specialized thing.

marcpanther
Автор

what if you need to change the data locally to then make a mutation? Will it be necessary Zustand/Redux/useState, or react query provides a solution for this?

fhorray