Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Comercial
    • Calculadora

0

128
Vistas
How can I use re-fetch data in Next.js when an endpoint is hit?

I am using a webhook which triggers a request to an URL when a message is POST in the channel. I am using getServerSideProps to fetch data from the server,

export async function getServerSideProps({ req }) {
  console.log("\x1b[36m%s\x1b[0m", "get req to serverside");
  let messages = {};
if (req.method === "GET") {
messages = await getMessages(process.env.NEXT_PUBLIC_ROCKET_CHAT_CONF_RID,req.cookies)
} 

if (req.method === "POST") {
// does a re-fetch but it is not sending me the data back
messages = await getMessages(process.env.NEXT_PUBLIC_ROCKET_CHAT_CONF_RID,req.cookies)
}
  return {
    props: {
      messages,
      cookies: req.cookies,
    },
  };
}

As quoted here in the doc,

Server-side Rendering: The HTML is generated on each request. To make a page use Server-side Rendering, export getServerSideProps. Because Server-side Rendering results in slower performance than Static Generation, use this only if absolutely necessary.

How can I re-fetch data and make the message sending part realtime?

7 months ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos