Created
March 27, 2017 01:23
-
-
Save guzmonne/a60a3dfb7194925aecad5327f981f453 to your computer and use it in GitHub Desktop.
Helper component to avoid a race condition between windows.
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 from 'react'; | |
import ReactDOM from 'react-dom'; | |
import Root from './containers/Root.js'; | |
import configureStore from './store/configureStore.js' | |
import './_styles/index.css'; | |
const Loading = () => (<h1>Loading...</h1>) | |
const store = configureStore() | |
class Starter extends React.Component { | |
constructor(){ | |
super() | |
this.state = { | |
serverUp: false, | |
} | |
} | |
componentDidMount(){ | |
const tryServer = () => { | |
console.log('Trying server.') | |
fetch('http://localhost:3000/on') | |
.then(() => this.setState({serverUp: true})) | |
.catch(() => setTimeout(tryServer, 1000)) | |
} | |
tryServer() | |
} | |
render() { | |
return ( | |
this.state.serverUp | |
? <Root store={store}/> | |
: <Loading /> | |
) | |
} | |
} | |
ReactDOM.render( | |
<Starter />, | |
document.getElementById('root') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment