Skip to content

Commit

Permalink
Fix typo and add comment to next/image SyntheticEvent (#41480)
Browse files Browse the repository at this point in the history
- Fix typo 
- Add comment
- Link back to react docs
- Remove unnecessary variable
  • Loading branch information
styfle committed Oct 17, 2022
1 parent a75b323 commit e61820e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/next/client/image.tsx
Expand Up @@ -268,11 +268,14 @@ function handleLoading(
setBlurComplete(true)
}
if (onLoadRef?.current) {
// Since we don't have the SyntheticEvent here,
// we must create one with the same shape.
// See https://reactjs.org/docs/events.html
const event = new Event('load')
Object.defineProperty(event, 'target', { writable: false, value: img })
let prevented = false
let stopped = false
const sytheticEvent = {
onLoadRef.current({
...event,
nativeEvent: event,
currentTarget: img,
Expand All @@ -288,8 +291,7 @@ function handleLoading(
stopped = true
event.stopPropagation()
},
}
onLoadRef.current(sytheticEvent)
})
}
if (onLoadingCompleteRef?.current) {
onLoadingCompleteRef.current(img)
Expand Down

0 comments on commit e61820e

Please sign in to comment.