Next.js Discord

Discord Forum

Change <Image /> src according to screen size

Unanswered
PepeW posted this in #help-forum
Open in Discord
With a normal <img /> tag we can change images according to the screensize using the srcSet attribute.
Is there a way to do a similar thing with the <Image /> component in NextJS 13 ? (Maybe using a loader ?)

4 Replies

up
up
please do not bump more than once a day per rule 8
for people having the same problem, here's how I did it:
<picture>
  <source
    srcSet="desktop.jpeg"
    media="(min-width: 1024px)" // 1024px and above
  />
  <Image
    src="mobile.jpeg"
    alt="pictures"
    fill
  />
</picture>