Skip to content

Commit 08b6ec0

Browse files
committed
docs: update controller on route change
1 parent 1b16df2 commit 08b6ec0

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
};

documentation/src/theme/Root.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import React from 'react';
22
import { ParallaxProvider } from 'react-scroll-parallax';
3+
import { ParallaxRouteUpdate } from '../components/parallax-route-update';
34

45
// 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+
);
713
}
814

915
export default Root;

0 commit comments

Comments
 (0)