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

101
Views
Magnify on hover of image in React

I am using react for my project and the requirement is to get magnified view on hover and function call onLoad on load of img and onError on failure of load. I tried various packages but none gives me both of the above simultaneously.

Here is the packages I tried

import { GlassMagnifier } from "react-image-magnifiers";

{
    /* This one tried with react-image-magnifiers doesn't give onError event to control if image load fails*/
}

export const Image = React.memo(() => {
    const onLoad = () => {
        console.log("inside load");
        // do some stuff
    };

    const onError = err => {
        console.log("inside error");
        // do some stuff
    };

    return (
        <>
            <span hidden={!loaded}>
                <GlassMagnifier
                    imageAlt="certificate-preview"
                    imageSrc="https://some-link"
                    className="image"
                    onImageLoad={() => onLoad()}
                    magnifierSize="35%"
                />
            </span>
        </>
    );
});

This one tried with react-image-magnify didn't give expected glass view

import ReactImageMagnify from "react-image-magnify";

{
    /* This one tried with react-image-magnify didn't give expected glass view*/
}

export const Image = React.memo(() => {
    const onLoad = () => {
        console.log("inside load");
        // do some stuff
    };

    const onError = err => {
        console.log("inside error");
        // do some stuff
    };

    const prop = {
        smallImage: {
            src,
            width: 200,
            height: 300,
            alt: "certificate-preview",
            onLoad,
            onError: err => {
                console.log("In small 1st err");
                onError(err);
            },
        },
        largeImage: {
            src: "https://some-link",
            width: 100,
            height: 300,
            alt: "certificate-preview",
            onLoad,
            onError: err => {
                onError(err);
            },
        },
        enlargedImageStyle: {
            objectFit: "contain",
        },
    };

    return (
        <>
            <ReactImageMagnify {...prop} />
        </>
    );
});

This is the expected view Expected view

I may be missing something. Any help would be highly appreciable.

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!