How to automatically set height and width of image with NextJS

Viewed 24

The Image component provided by Next.js requires you to set the image's intristic width and height.

import Image from 'next/image'

export default function Index(props) {
    return (
        <div>                   
            <Image
                layout="intrinsic"
                width={774}
                height={1161}
                src="https://images.unsplash.com/photo-1662572163236-630fd5bcc99d?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=687&q=80"
            />
        </div>
    )
}

How can I automatically get the intrinsic image height and width so that I do not have to manually figure out the intrinsic size each time I use the image component?

0 Answers
Related