Skip to content

Instantly share code, notes, and snippets.

@St2r
Last active November 8, 2021 15:22
Show Gist options
  • Save St2r/8486b61aec5b786d4c6b65a8b6189819 to your computer and use it in GitHub Desktop.
Save St2r/8486b61aec5b786d4c6b65a8b6189819 to your computer and use it in GitHub Desktop.
make DOM event handled after React hydrate
const handleLoad = (
e: SyntheticEvent<HTMLImageElement>
) => {
console.log('onload');
};
return (
<img
ref={(input: HTMLImageElement | null) => {
if (input) {
(input.onload as any) = handleLoad;
imgRef.current = input;
}
}}
src={'example.webp'}
/>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment