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

105
Views
React blur-up only without cache

I'm building an app in Next.JS with React and we have an image blur-up implementation that works well with one issue. Here's a sketch of the implementation:

function ImageElement({src, srcSet, sizes, base64}){
  const [loaded, setLoaded] = useState(false);
  const imgRef = useRef();

  useEffect(() => {
    if(imgRef.current.complete){
      setLoaded(true)
    }
  }, []);

  return (
    <div>
      <img className="placeholder" src={base64} alt="" />
      <img
        className="regular"
        srcSet={srcSet}
        sizes={sizes}
        loading="lazy"
        decoding="async"
        style={{
          opacity: loaded ? 1 : 0
        }}
        ref={imgRef}
        onLoad={handleLoaded}
      />
    </div>
  );

There's also a transition: opacity 500ms ease 0s rule on the image and various other css to make it work (these don't seem to be the source of the issue though).

The problem I'm having is that because the opacity always starts at 0, it does a blur-up every time the page loads, even when the image is cached and it doesn't need to. I want to find a way to check that it's cached before it renders the first time but nothing I've tried has worked.

I tried a function that creates an img element and checks if it's loaded but it doesn't seem to work when I build and I get this error message in dev mode:

Prop `style` did not match. Server: "opacity:0" Client: "opacity:1"

Is there something I'm missing?.

about 4 years ago · Juan Pablo Isaza
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!