-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathgatsby-browser.js
33 lines (30 loc) · 1 KB
/
gatsby-browser.js
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
/* globals window CustomEvent */
import React from 'react';
import AppProvider from 'store/provider';
import { Location } from '@reach/router';
import posed, { PoseGroup } from 'react-pose';
import { timeout } from 'constants/transition';
// React Context in Browser
export const wrapRootElement = ({ element }) => {
return <AppProvider>{element}</AppProvider>;
};
// Page Transitions
// Note: I would really like to use `replaceComponentRenderer`
// here, however it breaks all the GraphQL queries on build.
export const wrapPageElement = ({ element, props }) => {
const RoutesContainer = posed.div({
enter: { opacity: 1, delay: timeout, delayChildren: timeout },
exit: { opacity: 0 },
});
// To enable page transitions on mount / initial load,
// use the prop `animateOnMount={true}` on `PoseGroup`.
return (
<Location>
{({ location }) => (
<PoseGroup>
<RoutesContainer key={location.pathname}>{element}</RoutesContainer>
</PoseGroup>
)}
</Location>
);
};