-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-browser.js
More file actions
41 lines (34 loc) · 1.12 KB
/
Copy pathgatsby-browser.js
File metadata and controls
41 lines (34 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import React from "react";
import { MenuProvider } from "./src/components/MenuContext";
import { AnimatePresence } from "framer-motion";
import "@fontsource/inter/300.css";
import "@fontsource/inter/400.css";
import "@fontsource/inter/500.css";
import "@fontsource/inter/700.css";
export function wrapRootElement({ element }) {
return <MenuProvider>{element}</MenuProvider>;
}
export function wrapPageElement({ element }) {
return <AnimatePresence exitBeforeEnter>{element}</AnimatePresence>;
}
export const shouldUpdateScroll = ({
routerProps: { location },
getSavedScrollPosition,
}) => {
// transition duration from `layout.js` * 1000 to get time in ms
// * 2 for exit + enter animation
const TRANSITION_DELAY = 0.5 * 1000 * 2;
// If its a normal route
if (location.action === "PUSH") {
window.setTimeout(() => window.scrollTo(0, 0), TRANSITION_DELAY);
}
// If we used the browsers forwards or back button
else {
const savedPosition = getSavedScrollPosition(location) || [0, 0];
window.setTimeout(
() => window.scrollTo(...savedPosition),
TRANSITION_DELAY
);
}
return false;
};