Skip to content

Instantly share code, notes, and snippets.

@BiosBoy
Created January 13, 2019 11:23
Show Gist options
  • Select an option

  • Save BiosBoy/c562a7c549a4641e506d781a685db108 to your computer and use it in GitHub Desktop.

Select an option

Save BiosBoy/c562a7c549a4641e506d781a685db108 to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOM from 'react-dom';
import RedBox from 'redbox-react';
import store from './controller/store';
import history from './controller/history';
import AppContainer from './containers/AppContainer';
const ENTRY_POINT = document.querySelector('#react-app-root');
// creating starting endpoint for app.
const render = () => {
ReactDOM.render(<AppContainer store={store} history={history} />, ENTRY_POINT);
};
// this will help us understand where the problem is located once app will fall.
const renderError = error => {
ReactDOM.render(<RedBox error={error} />, ENTRY_POINT);
};
// register serviceWorkers if available
if ('serviceWorker' in navigator) {
navigator.serviceWorker
.register('./serviceWorker.js')
.then(registration => {
console.log('Excellent, registered with scope: ', registration.scope);
})
.catch(e => console.error('ERROR IN SERVICE WORKERS: ', e));
}
// This code is excluded from production bundle
if (__DEV__) {
// ========================================================
// DEVELOPMENT STAGE! HOT MODULE REPLACE ACTIVATION!
// ========================================================
const devRender = () => {
if (module.hot) {
module.hot.accept('./containers/AppContainer', () => render());
}
render();
};
// Wrap render in try/catch
try {
devRender();
} catch (error) {
console.error(error);
renderError(error);
}
} else {
// ========================================================
// PRODUCTION GO!
// ========================================================
render();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment