import React, { PureComponent } from 'react' import Helmet from 'react-helmet' import styles from './HostnameCheck.module.scss' const allowedHosts = [ 'matthiaskretschmann.com', 'beta.matthiaskretschmann.com', 'localhost' ] export default class HostnameInfo extends PureComponent { checkAllowedHost = () => { if (typeof window !== 'undefined' && window.location) { return allowedHosts.includes(window.location.hostname) } } state = { // default to true so SSR builds never show the banner isAllowedHost: true } componentDidMount() { const isAllowedHost = this.checkAllowedHost() this.setState({ isAllowedHost }) } render() { // return nothing if we're on an allowed host if (this.state.isAllowedHost) return null return ( <> ) } }