I really liked ur article, but i am struggling to make it work with array of images, could you please take a look at my codesandbox? codesandbox.io/s/image-fallback-cvvbf Do you have any suggestions?
Hi!
Looks like you're using a the useProgressiveImage hook inside of a loop, which violates the rules of hooks.
useProgressiveImage
Instead, create a new component ProgressiveImage, which calls this hook for each image. It'll look like this:
ProgressiveImage
const ProgressiveImage = (props) => { const src = useProgressiveImage({ src: props.src, fallbackSrc: props.fallbackSrc }); if (!src) return null; return <img className="hero" alt={props.alt} src={src} />; }; const Images = ({ images }) => { return ( <div> {images.map(image => <ProgressiveImage key={image} src={image.src} fallbackSrc={image.fallbackSrc} />)} </div> ); }
it worked, thank you:)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
I really liked ur article, but i am struggling to make it work with array of images, could you please take a look at my codesandbox? codesandbox.io/s/image-fallback-cvvbf Do you have any suggestions?
Hi!
Looks like you're using a the
useProgressiveImage
hook inside of a loop, which violates the rules of hooks.Instead, create a new component
ProgressiveImage
, which calls this hook for each image. It'll look like this:it worked, thank you:)