Created
          February 22, 2020 14:28 
        
      - 
      
- 
        Save skolhustick/bb2c43bb26496c114ef238a4aca83d44 to your computer and use it in GitHub Desktop. 
    NextJS styled-components _app.js
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import React, { useState, useEffect } from 'react' | |
| import useDarkMode from 'use-dark-mode' | |
| import { ThemeProvider } from 'styled-components' | |
| import { lightTheme, darkTheme } from '../theme' | |
| const MyApp = ({ Component, pageProps }) => { | |
| const [isMounted, setIsMounted] = useState(false) | |
| const darkMode = useDarkMode(true) | |
| const theme = darkMode.value ? darkTheme : lightTheme | |
| useEffect(() => { | |
| setIsMounted(true) | |
| }, []) | |
| return ( | |
| <ThemeProvider theme={theme}> | |
| <button onClick={darkMode.enable}>DARK MODE</button> | |
| <button onClick={darkMode.disable}>LIGHT MODE</button> | |
| {isMounted && <Component {...pageProps} />} | |
| </ThemeProvider> | |
| ) | |
| } | |
| export default MyApp | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment