File tree Expand file tree Collapse file tree 2 files changed +25
-2
lines changed
components/parallax-route-update Expand file tree Collapse file tree 2 files changed +25
-2
lines changed Original file line number Diff line number Diff line change
1
+ import { useEffect } from 'react' ;
2
+ import { useLocation } from 'react-router-dom' ;
3
+ import { useParallaxController } from 'react-scroll-parallax' ;
4
+
5
+ function useUpdateControllerOnRouteChange ( ) {
6
+ const location = useLocation ( ) ;
7
+ const parallaxController = useParallaxController ( ) ;
8
+
9
+ useEffect ( ( ) => {
10
+ parallaxController . update ( ) ;
11
+ } , [ location . pathname ] ) ;
12
+ }
13
+
14
+ export const ParallaxRouteUpdate = ( ) => {
15
+ useUpdateControllerOnRouteChange ( ) ;
16
+ return null ;
17
+ } ;
Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import { ParallaxProvider } from 'react-scroll-parallax' ;
3
+ import { ParallaxRouteUpdate } from '../components/parallax-route-update' ;
3
4
4
5
// Default implementation, that you can customize
5
- function Root ( { children } ) {
6
- return < ParallaxProvider > { children } </ ParallaxProvider > ;
6
+ function Root ( props ) {
7
+ return (
8
+ < ParallaxProvider >
9
+ < ParallaxRouteUpdate />
10
+ { props . children }
11
+ </ ParallaxProvider >
12
+ ) ;
7
13
}
8
14
9
15
export default Root ;
You can’t perform that action at this time.
0 commit comments