Providing initial data to useSWRSubscription? #2749
Unanswered
dasveloper
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
-
I'm using Next.js with Pusher to provide realtime communication. The events are also being stored in a database as they are sent. This is the code I'm using to subscribe to these Pusher events:
This works fine for getting all new Pusher events, however, I want to load all previous events from my database as well (i.e. chat history). I have an API route
/api/events/:channelId
I can fetch these previous events from. Now I want to concat any new Pusher events to the previous events so I have a full history, which I can do with something like this:But this is rather ugly in my opinion. It would also be nice to revalidate the 'oldEvents' at some point in case the subscription gets out of sync with the stored events somehow. Is there a better way to handle this with
useSWRSubscription
, or should I just be using regular useSWR and trigger mutations on Push events to revalidate?Beta Was this translation helpful? Give feedback.
All reactions