UI not updating first with swr mutate ( next.js project ) #1198
Unanswered
Diego-Mike
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.
-
Hi comunnity !!
I'm doing a project for the first time with next.js and SWR, and i'ts been quite great so far since i don't have to use global state managment like redux or whatever.
However, in my journey trying to update the data in the cache of my SWR, i'm having problems since i'm only have been able to update my UI with mutate once ): ( before hitting the endpoint in my API then revalidating the data ).
So, let me give you some context, i'm doing a facebook clone, and whenever i want to click the like button, i want the UI to update at time, then hitting the endpoint of my API in order to check if data in the cache is right.
When i tried to do that, UI only updates after 4-5 seconds, it's like cache it's not updating
Let me show you some code
These are the interfaces of my data ( so you can understand what i'm doing )
Here i'm making the call to get all posts with getStaticProps
Here's where i want to update the cache fast in the UI ( function to Like a post )
So what happens after onClick={LikePub} is that everything works fine but, it takes to 4-5 seconds ( as i already explained ) to update the UI, i tried to change code multiple times, but couldn't acomplish what i want, what am i doing wrong ?
I'm kinda noob at this library yet, so if you know a way to help, me i would thank you !
Thanks for your time comunnity
Beta Was this translation helpful? Give feedback.
All reactions