M
M
mosikus2019-12-01 20:59:30
React
mosikus, 2019-12-01 20:59:30

How to make a stub before loading an image (onLoad)?

Hello. On the page, you need to use 3 different images and make a stub for each image before uploading the image. The method below does not work, namely, the image is not displayed, what is wrong?

const [isLoading, setLoading] = React.useState(false);
const handleOnLoad = () => {
    setLoading(true);
}

{isLoading === true ? (<img onLoad={handleOnLoad } src="https://i.5sfer.com/post/postImage/thumb-8ipwnn.jpg"/>) : (<div>*Заглушка*</div>)}

https://codesandbox.io/s/loving-worker-dc1x5

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lnked, 2019-12-01
@mosikus

You can’t load a picture with such logic either, since you have isLoading false, img is not rendered and onLoad is not called

I
Ice, 2019-12-01
@IceRD

Example of correct usage https://codesandbox.io/s/fragrant-glade-8huj6

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question