#Threeeaaadddd

1 messages · Page 1 of 1 (latest)

thorny sundial
#

boom

hazy lodge
#

yo

thorny sundial
#

okok

#

re post the code and pics

#

so my feeble phone can scroll

hazy lodge
#

shouldn't useEffect rerender when getPosts gets revalidated

thorny sundial
#

and Post is page.tsx correct?

hazy lodge
#

ofc

thorny sundial
#

hmmm

#

yes it should but

hazy lodge
thorny sundial
#

ahhhhh

#

this is what i needed

hazy lodge
thorny sundial
#

so the issue here is that you need to actually poll the page for it to revalidate

#

i would do a setInterval (janky but this is the example)

#

and poll the page every couple seconds

thorny sundial
#

revalidate 0, and refresh on new posts, but its never gonna get new posts

#

so its never gonna refresh

hazy lodge
#

nextjs docs says otherwise

thorny sundial
#

because something needs to initiate the action

hazy lodge
thorny sundial
#

unless EVERY SINGLE refresh has a new change

hazy lodge
#

right?

thorny sundial
#

right!

hazy lodge
#

so we cry about it?

thorny sundial
#

so do a setInterval

hazy lodge
#

wont that be the same is reloading

thorny sundial
#

iin this basic example yes

#

but

#

if you wrap the feed as a client component that keeps a “newest post” state

hazy lodge
#

that's kinda janky what do ppl usually do instead of polling or websockets

thorny sundial
#

you can implement a “show new posts” button

#

that way it does get the new posts but doesnt add them to the dom till the user asks it to

#

like the blue bird

hazy lodge
#

ah i see

#

dope idea

thorny sundial
hazy lodge
thorny sundial
#

those are the 3 ways

#

honestly

hazy lodge
#

but polling wont work

#

in my example

#

cuz it needs a trigger

#

but how do ppl use polling

thorny sundial
#

yes. that was my original point

#

my original point was that you want client only features but your data is server side

#

you could make an api route and query your own api as a client component

#

that just gives a post ID

hazy lodge
#

so if the data is sever side i cant do polling

thorny sundial
#

and if the post id !== local post id then router refresh

thorny sundial
#

hahaa

hazy lodge
#

thanks man

#

so much valiable stuff

thorny sundial
#

its new logic. so everyone is trying to learn how to slice the pie the right way together

hazy lodge
#

so usually to do polling u need an "api route" to update the data on the client

#

which is kinda bad for nextjs cuz that whole point is stuff to be server

#

but whatever

thorny sundial
hazy lodge
#

unless we use server actions

#

which i wont

#

too lazy to learn

thorny sundial
#

nono

#

server actions are fantastic

#

and have a use

#

this isnt it

hazy lodge
#

oh

#

i see

#

so either refresh or api route with polling or web sockets

#

these are the options

thorny sundial
#

think of server actions as a shortcut api without needing to write out a whole api to make a server call

hazy lodge
#

or i can do a huge iq move

#

just update the state visually

#

the like btn

#

and the server will update

#

without them connecting

thorny sundial
hazy lodge
#

do u have blue bird?

#

btw thanks dude

#

understood a lot

thorny sundial
hazy lodge
thorny sundial
hazy lodge
#

5 seconds

thorny sundial
#

ts or just js

hazy lodge
thorny sundial
#

answer the question haha

#

is it ts or js

hazy lodge
#

oh ts

#

btw does the app look cool?

thorny sundial
#

inside your useEffect

const handle = setInterval(() => {
  fetch("https://chubbybunny.com/api/posts?userId=tinyTim")
    .then(res => res.text().then(
      newPostId => {
        if (newPostId !== latestPostId) {
          setLatestPostId(newPostId)
        }
      })
), 5_000)

return () => {
  clearInterval(handle)
}
#

sorry had to post so i could see where the formatting was at

#

phone coding hard

hazy lodge
#

ah i see

#

thanks lol

thorny sundial
#

also make sure to clear interval

#

on return

#

like that

hazy lodge
#

close thread

thorny sundial
hazy lodge
#

an hour passed

thorny sundial
#

nono

#

i am saying i just set it for me… but i think its per person

#

unless i have unilateral control since i made the thread

hazy lodge
#

ahh

#

i can leave the thread there is an option

#

u have that too?

thorny sundial
#

ooo good catch