Next.js Discord

Discord Forum

Can I manipulate a component by an nextjs api?

Unanswered
Tramp ant posted this in #help-forum
Open in Discord
Tramp antOP
My question here is if I call an endpoint that I created inside nextjs can I pass the request body to components and render them on client side?

So it will be:

Call /test-api > Receive on route handler > Send to <ComponentToRenderBody / >

12 Replies

@Tramp ant My question here is if I call an endpoint that I created inside nextjs can I pass the request body to components and render them on client side? So it will be: Call /test-api > Receive on route handler > Send to <ComponentToRenderBody / >
yes and no.

Like you expect it does not work. However you can call your endpoint and the endpoint return the data that is needed for the component to render.

So, that would work: Call /test-api > Receive on route handler > Return data where it was requested > Render to <ComponentToRenderBody / >
Tramp antOP
Yeah, my idea was kinda of creating a webhook but it will not work. thx tho
@Tramp ant Yeah, my idea was kinda of creating a webhook but it will not work. thx tho
a webhook returning an component? No, please not and thanks god, that that does not work 🙏
@Tramp ant Yeah, my idea was kinda of creating a webhook but it will not work. thx tho
Sun bear
what are you trying to achieve with this?
@Sun bear what are you trying to achieve with this?
Tramp antOP
its like a notification system, our sysadmin would create a notification for the users and then when our backend ( not in nextjs ) receives and creates the notification then it would call an endpoint on nextjs and therefore render in the notification tab
there are other solutions for this of course, but I would like to know the viability of this one
@B33fb0n3 a webhook returning an component? No, please not and thanks god, that that does not work 🙏
Tramp antOP
it wouldnt return a component just the json
I think this solution would be cool as an option to replace websocket or calling an endpoint every x seconds to check if theres something new, you know?
perhaps you could use ISR?
(not like live updating but would update data for the next load)
@Tramp ant its like a notification system, our sysadmin would create a notification for the users and then when our backend ( not in nextjs ) receives and creates the notification then it would call an endpoint on nextjs and therefore render in the notification tab
you are looking for real time communication. normal http endpoints are not a good fit. you either use real time (websocket for example) or polling (in the notification component, ping the server every x seconds to check if there are new notifications)