Created
October 22, 2016 10:16
-
-
Save glennreyes/48f8b2f4e6b5d9399ca92e13e07dbedd to your computer and use it in GitHub Desktop.
Example using redbox-react
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
/* @flow */ | |
/* eslint-disable global-require, no-console */ | |
import React from 'react'; | |
import { render } from 'react-dom'; | |
import Redbox from 'redbox-react'; | |
const clearConsole = () => { | |
if (typeof console.clear === 'function') { | |
console.clear(); | |
} | |
}; | |
const renderApp = () => { | |
clearConsole(); | |
require('../src'); | |
}; | |
const renderErrorWithRedbox = (error) => { | |
render( | |
<Redbox error={error} />, | |
document.getElementById('root'), | |
); | |
console.error(error); | |
}; | |
try { | |
renderApp(); | |
} catch (error) { | |
renderErrorWithRedbox(error); | |
} | |
if (module.hot && typeof module.hot.accept === 'function') { | |
// Enable webpack HMR and just rerun this module | |
module.hot.accept(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment