mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
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
19 lines
559 B
JavaScript
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>
|
|
)
|
|
}
|