Approach for handling web-sockets with react-query #2105
Unanswered
Manish3323
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I am looking for suggestions / ideas for consuming web socket based callback api in frontend.
Dummy project setup looks like following :
we have a callback based web socket api in our library, which streams backend data (say todo list).
API looks like this :
At frontend : we are trying out 2 approaches to consume this above api.
one with react-query & another without (i.e using custom react-hooks)
1st approach using react-query looks something like this
imp thing to notice here that we are using
useQuery
only for client-side state maintenance & not actually making backend calls in useQueryLet's say,
useTodoStream
will be plugged in parentComponent of react application tree.&
useTodoList
will be consumed by component1 & component2.in this approach,
2nd Approach involves useEffect, useContext hook
using this context + useEffect approach :
Question :
Do you see any advantage of using react-query over vanilla context+hook
Note that we already depend on react-query for other request/response and mutation API's
Beta Was this translation helpful? Give feedback.
All reactions