Last active
July 15, 2018 18:18
-
-
Save drenther/12d3cca3952cf874541ab7eca487d368 to your computer and use it in GitHub Desktop.
Header and Nav components
This file contains 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, { Component } from 'react'; | |
import Router from 'next/router'; | |
import Head from 'next/head'; | |
import Nav from './Nav'; | |
class Header extends Component { | |
state = { loading: false }; | |
componentDidMount() { | |
Router.onRouteChangeStart = () => { | |
this.setState({ loading: true }); | |
}; | |
Router.onRouteChangeComplete = () => { | |
this.setState({ loading: false }); | |
}; | |
Router.onRouteChangeError = () => { | |
this.setState({ loading: false }); | |
}; | |
} | |
render() { | |
return ( | |
<div className="header"> | |
<Head> | |
<meta charSet="UTF-8" /> | |
<meta name="description" content="An example PWA" /> | |
<meta name="viewport" content="width=device-width, initial-scale=1" /> | |
<meta name="theme-color" content="#302ecd" /> | |
<title>Movies PWA</title> | |
<link rel="manifest" href="/_next/static/manifest.json" /> | |
<link rel="icon" href="/static/favicon.ico" /> | |
<link rel="stylesheet" href="/_next/static/style.css" /> | |
</Head> | |
<Loader loading={this.state.loading} /> | |
<Nav /> | |
</div> | |
); | |
} | |
} | |
const Loader = ({ loading }) => <div className={loading ? 'loading-show' : ''} id="loader-bar" />; | |
export default Header; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment