Files
StevenandGitHub 4b50313fd9 feat: stabilize unstable_getImgProps() => getImageProps() (#60739)
This PR renames `unstable_getImgProps` to `getImageProps()` (originally
introduced in PR #51205).

Most feedback [after
announcing](https://twitter.com/leeerob/status/1674250190432116736)
looks positive so it seems like we can safely stabilize this API now.
Its unlikely to change.

I also added documentation with example usage.

Closes NEXT-2120
Fixes https://github.com/vercel/next.js/issues/56009
2024-01-17 18:28:49 -05:00

19 lines
559 B
JavaScript

import { getImageProps } from 'next/image'
export default function Page() {
const common = { alt: 'Hero', width: 400, height: 400, priority: true }
const {
props: { srcSet: dark },
} = getImageProps({ ...common, src: '/test.png' })
const {
props: { srcSet: light, ...rest },
} = getImageProps({ ...common, src: '/test_light.png' })
return (
<picture>
<source media="(prefers-color-scheme: dark)" srcSet={dark} />
<source media="(prefers-color-scheme: light)" srcSet={light} />
<img {...rest} />
</picture>
)
}