You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
upd: nevermind. It seems I had bad implementation of some of my components. Refactored the code and the problem is gone.
Hi guys.
I'm implementing a search functionality for products page.
Initially I load all products from database with useSWR.
When user enters a searchTerm and submits it, I call mutate function passing function that returns new data as an argument.
In networks I see that the mutate creates a new request to get new data that satisfies searchTerm but then it immediately sends another requests to load all data
Consider the following code:
constComponent=()=>{const{ data, mutate }=useSWR(MY_ENDPOINTS.GET);consthandleFormSubmit=(searchTerm)=>{mutate(async()=>{const{ data }=awaitaxios.post(MY_ENDPOINTS.POST,{ searchTerm });returndata});}return( ... )}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
upd: nevermind. It seems I had bad implementation of some of my components. Refactored the code and the problem is gone.
Hi guys.
I'm implementing a search functionality for products page.
Initially I load all products from database with
useSWR
.When user enters a
searchTerm
and submits it, I callmutate
function passing function that returns new data as an argument.In networks I see that the
mutate
creates a new request to get new data that satisfiessearchTerm
but then it immediately sends another requests to load all dataConsider the following code:
backend
Does anyone have a clue what's going on? How can I fix it?
https://vimeo.com/722481138/441633c4c3
Beta Was this translation helpful? Give feedback.
All reactions