How to trigger (from the server) a re-render of a React Server Component ?
Unanswered
Norwegian Lundehund posted this in #help-forum
Norwegian LundehundOP
React server component that render an external value :
I have code on the server constantly running :
Goal: all clients that currently have an http streaming session open, will see the new content of MyComponent.
// MyComponent.js
import { value } from 'Backend.js'
export default function MyComponent() {
return <h1>hello world {value}</h1>
}I have code on the server constantly running :
// Backend.js
export let value;
// co-routine always running on the server only
function loop() {
// change value every now and then
if (Math.random() > .5) {
value = Math.random();
// how to manually trigger re-render of components
// that render "value" in this case MyComponent.js
// ...
// The solution I'm currently thinking of is to use a websocket.
// The server will send a signal to the client, so the client
// will know it has to trigger a re-render (by calling router.refresh)
}
}Goal: all clients that currently have an http streaming session open, will see the new content of MyComponent.