I am working with Gatsby and have some code in my gatsby-browswer.js
file which is importing a theme, but the changes don’t reflect on my webpage.
My gatsby-browser
file:
JavaScript
x
23
23
1
import React from "react"
2
import { createGlobalStyle, ThemeProvider } from "styled-components"
3
import Theme from "./src/themes/theme"
4
5
const GlobalStyle = createGlobalStyle`
6
* {
7
box-sizing: border-box;
8
margin: 0;
9
padding: 0;
10
}
11
12
html, body {
13
font-family: ${props => props.theme.fonts.main};
14
height: 100%;
15
background-color: ${props => props.theme.colors.light1};
16
}
17
`
18
export const wrappedRootElement = ({ element }) => (
19
<ThemeProvider theme={Theme}>
20
<GlobalStyle />
21
{element}
22
</ThemeProvider>
23
)
My theme file:
JavaScript
1
35
35
1
export default {
2
fonts: {
3
main: "Muli, sans-serif",
4
code: "Roboto Mono, monospace",
5
},
6
colors: {
7
main1: "hsl(207, 70%, 59%)",
8
main2: "hsl(207, 70%, 94%)",
9
dark1: "hsl(227, 2%, 12%)",
10
dark2: "hsl(227, 2%, 26%)",
11
dark3: "hsl(227, 2%, 64%)",
12
light1: "hsl(0, 0%, 97%)",
13
light2: "hsl(0, 0%, 99%)",
14
},
15
breakpoints: {
16
mobile: "only screen and (max-width: 50rem)",
17
tablet: "only screen and (max-width: 65rem)",
18
},
19
spacings: {
20
xxSmall: ".25rem",
21
xSmall: ".5rem",
22
small: "1rem",
23
medium: "2rem",
24
large: "3rem",
25
xLarge: "4rem",
26
xxLarge: "6rem",
27
},
28
animations: {
29
button: "box-shadow 0.3s ease",
30
link: "color 0.2s ease",
31
},
32
shadows: {
33
shadow1: "0px 5px 20px rgba(30, 30, 31, 0.05)",
34
},
35
}
The page is a very simple “Hello World”, but when I check the font and everything else on the webpage, they seem to be the default ones.
Advertisement
Answer
The exported function should be called wrapRootElement
instead of wrappedRootElement
.