<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Luke Neff</title>
    <description>The latest articles on DEV Community by Luke Neff (@timewizard).</description>
    <link>https://dev.to/timewizard</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1022063%2F273f793d-064c-4f43-aa2d-92165b77b5f5.png</url>
      <title>DEV Community: Luke Neff</title>
      <link>https://dev.to/timewizard</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/timewizard"/>
    <language>en</language>
    <item>
      <title>NextJS 13: Custom @next/fonts with MaterialUI Themes</title>
      <dc:creator>Luke Neff</dc:creator>
      <pubDate>Tue, 07 Feb 2023 02:02:17 +0000</pubDate>
      <link>https://dev.to/timewizard/nextjs-13-custom-nextfonts-with-materialui-themes-2jj4</link>
      <guid>https://dev.to/timewizard/nextjs-13-custom-nextfonts-with-materialui-themes-2jj4</guid>
      <description>&lt;h2&gt;
  
  
  Custom Fonts with Next 13 and MUI
&lt;/h2&gt;

&lt;p&gt;NextJS 13 launches with an excellent new font loading pattern. This article will explain how to integrate this font loading pattern in your MaterialUI themes. Reading and understanding &lt;a href="https://nextjs.org/docs/basic-features/font-optimization" rel="noopener noreferrer"&gt;this&lt;/a&gt; official documentation from Next is important as an initial launch point for this article.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Adding @next/font
&lt;/h2&gt;

&lt;p&gt;Follow the &lt;a href="https://nextjs.org/docs/basic-features/font-optimization#usage" rel="noopener noreferrer"&gt;Next documentation&lt;/a&gt; to add the @next/font library via npm or yarn to your project.&lt;/p&gt;

&lt;h2&gt;
  
  
  2.  Diverge from documentation
&lt;/h2&gt;

&lt;p&gt;In the initial example, the Next documentation recommends importing and adding our custom font to the _app.js file like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// pages/_app.js
import { Inter } from '@next/font/google'

// If loading a variable font, you don't need to specify the font weight
const inter = Inter({ subsets: ['latin'] })

export default function MyApp({ Component, pageProps }) {
  return (
    &amp;lt;main className={inter.className}&amp;gt;
      &amp;lt;Component {...pageProps} /&amp;gt;
    &amp;lt;/main&amp;gt;
  )
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s replace this code with a simplified example that uses a MaterialUI theme as a wrapper:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//pages/_app.js
import { ThemeProvider } from "@mui/material";
import { lightTheme } from '../themes/light.theme'

export default function App({ Component, pageProps }) {
  return (
    &amp;lt;ThemeProvider theme={lightTheme}&amp;gt;
      &amp;lt;Component {...pageProps} /&amp;gt;
    &amp;lt;/ThemeProvider&amp;gt;
  )
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  3. Implement fonts inside theme
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// themes/lightTheme
import { createTheme } from "@mui/material";
import { Roboto } from '@next/font/google'

export const roboto = Roboto({
  weight: '400',
  subsets: ['latin'],
})

export const lightTheme = createTheme({
  typography: {
    fontFamily: 
      roboto.style.fontFamily,
      body1: {
        fontFamily: roboto.style.fontFamily,
      },
      // etc
  }
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And there you have it! Your custom font has been imported and added to your MaterialUI Theme, available throughout your application.&lt;/p&gt;

</description>
      <category>postman</category>
      <category>tooling</category>
      <category>howto</category>
    </item>
  </channel>
</rss>
