Skip to content

Commit 491ae26

Browse files
committed
fix: do nothing when ref is null
1 parent f9a28ed commit 491ae26

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/hooks/useParallax.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ export function useParallax<T extends HTMLElement>(props: ParallaxProps) {
2424
};
2525
newElement = controller?.createElement(options);
2626
setElement(newElement);
27+
} else if (ref.current === null) {
28+
// if the ref is null, do nothing
29+
return;
2730
} else {
2831
throw new Error(
2932
'You must assign the ref returned by the useParallax() hook to an HTML Element.'
@@ -35,7 +38,7 @@ export function useParallax<T extends HTMLElement>(props: ParallaxProps) {
3538
controller?.removeElementById(newElement.id);
3639
}
3740
};
38-
}, []);
41+
}, [ref.current]);
3942

4043
// update element
4144
useEffect(() => {

stories/Image/Image.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import styles from './Image.module.scss';
55
export const Image = (props) => {
66
const parallaxController = useParallaxController();
77
function handleLoad() {
8-
parallaxController.update();
8+
parallaxController?.update();
99
}
1010
return (
1111
<div className={styles.image}>

0 commit comments

Comments
 (0)