Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

384
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!