Skip to content

How do you change your top-level theme font family? #1511

Answered by lachlanjc
ryanblakeley asked this question in Q&A
Discussion options

You must be logged in to vote

Your exact implementation will depend a lot on the framework you're using & how you're architecting your app. However, if you wanted to do this in Next.js, here's how I might go about it:

// pages/_app.js
import * as React from 'react'

import defaultTheme from '../lib/DEFAULT-THEME'
import { ThemeProvider } from 'theme-ui'

const App = ({ Component, pageProps }) => {
  const [theme, setTheme] = React.useState(defaultTheme)
  React.useEffect(() => {
    fetch('')
      .then(res => res.json())
      .then(data => {
        theme.fonts.body = data.font
        setTheme(theme)
      })
  }, [/* leave blank to run on init, or add hooks/state/data dependencies here */])

  return (
    <Theme…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ryanblakeley
Comment options

Answer selected by ryanblakeley
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants