Resource preloading
A hero image, a font, a stylesheet: some resources are needed the moment a page renders. If the browser only discovers them when it reaches the markup, the fetch starts late and a visitor waits.
React lets you start the fetch earlier with preload from react-dom:
import { preload } from 'react-dom';
function Hero() {
preload('/hero.png', { as: 'image' });
return <img src="/hero.png" alt="Hero" />;
}
Call preload(href, { as }) during render. React records the resource and
inserts a matching <link rel="preload" as="…" href="…" /> into the document
<head>, which tells the browser to begin downloading before the element that
uses the resource is parsed. The as option must match the resource kind
(image, font, style, script, …) so the browser applies the right fetch
settings.
preload is idempotent: calling it twice with the same href and as inserts
one link. Call it from the component that needs the resource, and keep the
resource's own markup alongside it so the fetch and the element stay together.
Your job is to preload the hero image and render it.
Challenge
The hero image only starts downloading once the markup reaches it, which is late.
Export an App component from App.jsx that preloads the hero image with
preload('/hero.png', { as: 'image' }) from react-dom, then renders it as
<img src="/hero.png" alt="Hero" />.
The Test renders <App /> and looks for the hero image with src="/hero.png".
The starter renders a placeholder instead, so the Test fails.