Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

385
Vistas
Background image does not render on server (nextjs)

I am using NextJs. I want to apply a background image on the body and it should be rendered on the server-side.

Here is my code

Below is my App.js

import BodyStyle from '@components/Bodystyle';
return (
    <>
      <BodyStyle bgColor={`url("picture-url")`} />
<>);

Here is my BodyStyle.js

const BodyStyle = (props) => {
  const { bgColor } =
    props;
  return (
    <Head>
      <style>{`body { background: ${bgColor} no-repeat center center fixed; background-size: cover;`}</style>
    </Head>
  );

The background is applied to the body but not from SSR

But there is a twist if I just copy the code from BodyStyles.js and paste in app.js the background image renders fine on the server

Here is the example code of the App.js

import Head from 'next/head';

return (
  <Head>
        <style>{`body { background: url(${url}) no-repeat center center fixed; background-size: cover;`}</style>
      </Head> 
);

Attached screenshots Without background on SSR enter image description here

With the background on SSR enter image description here

What could be an issue? Any help

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

i think its because you use to set bgcolor when there isn't any props yet try using it inside an useEffect or like this code:

const BodyStyle = ({bgColor}) => {

  return (
    <Head>
      <style>{`body { background: ${bgColor} no-repeat center center fixed; background-size: cover;`}</style>
    </Head>
  );
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda