File tree Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Expand file tree Collapse file tree 3 files changed +13
-9
lines changed Original file line number Diff line number Diff line change 11import { ParallaxController } from 'parallax-controller' ;
22import { useEffect } from 'react' ;
33
4- export function useVerifyController ( controller : ParallaxController ) {
4+ export function useVerifyController ( controller : ParallaxController | unknown ) {
55 useEffect ( ( ) => {
66 const isServer = typeof window === 'undefined' ;
77 // Make sure the provided controller is an instance of the Parallax Controller
Original file line number Diff line number Diff line change @@ -14,8 +14,8 @@ export function Parallax(props: PropsWithChildren<ParallaxProps>) {
1414
1515 function _getElementOptions ( ) : CreateElementOptions {
1616 const useSpeedProp = typeof props . speed !== 'undefined' ;
17- const isHorizontal = controller . scrollAxis == 'horizontal' ;
18- const isVertical = controller . scrollAxis == 'vertical' ;
17+ const isHorizontal = controller ? .scrollAxis == 'horizontal' ;
18+ const isVertical = controller ? .scrollAxis == 'vertical' ;
1919
2020 let translateX = props . translateX ;
2121 let translateY = props . translateY ;
@@ -63,19 +63,23 @@ export function Parallax(props: PropsWithChildren<ParallaxProps>) {
6363
6464 // create element
6565 useEffect ( ( ) => {
66- const newElement = controller . createElement ( _getElementOptions ( ) ) ;
66+ const newElement = controller ? .createElement ( _getElementOptions ( ) ) ;
6767 setElement ( newElement ) ;
6868
69- return ( ) => controller . removeElementById ( newElement . id ) ;
69+ return ( ) => {
70+ if ( newElement ) {
71+ controller ?. removeElementById ( newElement . id ) ;
72+ }
73+ } ;
7074 } , [ ] ) ;
7175
7276 // update element
7377 useEffect ( ( ) => {
7478 if ( element ) {
7579 if ( props . disabled ) {
76- controller . resetElementStyles ( element ) ;
80+ controller ? .resetElementStyles ( element ) ;
7781 } else {
78- controller . updateElementPropsById (
82+ controller ? .updateElementPropsById (
7983 element . id ,
8084 _getElementOptions ( ) . props
8185 ) ;
Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ import { useContext } from 'react';
22import { ParallaxController } from 'parallax-controller' ;
33import { ParallaxContext } from '../context/ParallaxContext' ;
44
5- export function useController ( ) : ParallaxController | { } {
5+ export function useController ( ) : ParallaxController | null {
66 const parallaxController = useContext ( ParallaxContext ) ;
77 const isServer = typeof window === 'undefined' ;
88 if ( isServer ) {
9- return { } ;
9+ return null ;
1010 }
1111
1212 if ( ! parallaxController ) {
You can’t perform that action at this time.
0 commit comments