This repository has been archived by the owner on Jun 21, 2023. It is now read-only.
forked from vercel/next.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
onLoadingComplete()
prop to Image component (vercel#26824)
This adds a new prop, `onLoadingComplete()`, to handle the most common use case of `ref`. I also added docs and a warning when using `ref` so we recommend the new prop instead. - Fixes vercel#18398 - Fixes vercel#22482
- Loading branch information
Showing
4 changed files
with
100 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
test/integration/image-component/default/pages/on-loading-complete.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useState } from 'react' | ||
import Image from 'next/image' | ||
|
||
const Page = () => ( | ||
<div> | ||
<h1>On Loading Complete Test</h1> | ||
<ImageWithMessage id="1" src="/test.jpg" /> | ||
<ImageWithMessage | ||
id="2" | ||
src={require('../public/test.png')} | ||
placeholder="blur" | ||
/> | ||
</div> | ||
) | ||
|
||
function ImageWithMessage({ id, src }) { | ||
const [msg, setMsg] = useState('[LOADING]') | ||
return ( | ||
<> | ||
<Image | ||
id={`img${id}`} | ||
src={src} | ||
width="400" | ||
height="400" | ||
onLoadingComplete={() => setMsg(`loaded img${id}`)} | ||
/> | ||
<p id={`msg${id}`}>{msg}</p> | ||
</> | ||
) | ||
} | ||
|
||
export default Page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters