Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use the onLoad event? #122

Open
bearsworth opened this issue Jul 10, 2022 · 1 comment
Open

How to use the onLoad event? #122

bearsworth opened this issue Jul 10, 2022 · 1 comment

Comments

@bearsworth
Copy link

Is it possible to trigger the onLoad event somehow? We're trying to put a spinner for larger images, but am unable to figure out how to implement this event on the component.

Thanks.

@explaingarlic
Copy link

Had the same issue, the way you do this is with the imgAttributes prop.

My example:

// me using my component...
<LazyInnerZoomImage
  src={`https://mysite.pl${activeImage}`}
  zoomSrc={activeImage}
  imgAttributes={{
    className: "rounded-[20px]",
    style: {
      objectFit: "contain",
      width: "100%",
      height: "100%",
    },
  }}
  hasSpacer={false}
  hideCloseButton
  zoomPreload
/>

that component looks like this:

export function LazyInnerZoomImage({ ...props } : InnerImageZoomProps) {
    const [isLoaded, setIsLoaded] = useState(false);
    const [isError, setIsError] = useState(false);

    return (
        <>
        {!isLoaded && !isError && <LoadingIcon className="text-black mt-4 ms-4"/>}
        <InnerImageZoom
            {...props}
            imgAttributes={{
                onLoad: () => setIsLoaded(true),
                onError: () => setIsError(true)
            }}
        />
        </>
    )
}

hope that helps :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants