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 1
1
import { ParallaxController } from 'parallax-controller' ;
2
2
import { useEffect } from 'react' ;
3
3
4
- export function useVerifyController ( controller : ParallaxController ) {
4
+ export function useVerifyController ( controller : ParallaxController | unknown ) {
5
5
useEffect ( ( ) => {
6
6
const isServer = typeof window === 'undefined' ;
7
7
// 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>) {
14
14
15
15
function _getElementOptions ( ) : CreateElementOptions {
16
16
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' ;
19
19
20
20
let translateX = props . translateX ;
21
21
let translateY = props . translateY ;
@@ -63,19 +63,23 @@ export function Parallax(props: PropsWithChildren<ParallaxProps>) {
63
63
64
64
// create element
65
65
useEffect ( ( ) => {
66
- const newElement = controller . createElement ( _getElementOptions ( ) ) ;
66
+ const newElement = controller ? .createElement ( _getElementOptions ( ) ) ;
67
67
setElement ( newElement ) ;
68
68
69
- return ( ) => controller . removeElementById ( newElement . id ) ;
69
+ return ( ) => {
70
+ if ( newElement ) {
71
+ controller ?. removeElementById ( newElement . id ) ;
72
+ }
73
+ } ;
70
74
} , [ ] ) ;
71
75
72
76
// update element
73
77
useEffect ( ( ) => {
74
78
if ( element ) {
75
79
if ( props . disabled ) {
76
- controller . resetElementStyles ( element ) ;
80
+ controller ? .resetElementStyles ( element ) ;
77
81
} else {
78
- controller . updateElementPropsById (
82
+ controller ? .updateElementPropsById (
79
83
element . id ,
80
84
_getElementOptions ( ) . props
81
85
) ;
Original file line number Diff line number Diff line change @@ -2,11 +2,11 @@ import { useContext } from 'react';
2
2
import { ParallaxController } from 'parallax-controller' ;
3
3
import { ParallaxContext } from '../context/ParallaxContext' ;
4
4
5
- export function useController ( ) : ParallaxController | { } {
5
+ export function useController ( ) : ParallaxController | null {
6
6
const parallaxController = useContext ( ParallaxContext ) ;
7
7
const isServer = typeof window === 'undefined' ;
8
8
if ( isServer ) {
9
- return { } ;
9
+ return null ;
10
10
}
11
11
12
12
if ( ! parallaxController ) {
You can’t perform that action at this time.
0 commit comments