Coding task · JavaScript and React course · Module 9: Modern React Hooks

Practice: Lazy Loading Images

loading="lazy" is native lazy loading of images: the browser itself checks when the image gets close to the screen. The onLoad event means the image is there, onError that it failed. In both cases you change the component state with setStatus.

Task

The gallery shows pictures of three planets. Every picture has a small, blurred thumbnail visible right away and a full image that appears only after it has loaded. Complete the PlanetImage component: ___BLANK1___ is the value of the loading attribute that makes the browser download the full image only when it gets close to the screen, ___BLANK2___ is the status set after the load event (the thumbnail disappears and the picture becomes visible), and ___BLANK3___ is the call that sets the status 'error' after the error event. Every picture has its own state, and an error shows a message with the planet name.