Created
August 9, 2016 14:42
-
-
Save leonardoo/5744050a7e2c627b286b34a1158727a4 to your computer and use it in GitHub Desktop.
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
const InputBox = React.createClass({ | |
getInitialState: function() { | |
return {data: [], interval: undefined}; | |
}, | |
componentDidMount: function() { | |
const inverval = setInterval(this.update, 5000); | |
this.setState({inverval}); | |
}, | |
componentWillUnmount: function() { | |
clearInterval(this.state.inverval); | |
this.setState({interval:undefined}); | |
}, | |
update: function(){ | |
const {data} = this.state; | |
fetch('http://localhost:8181/data') | |
.then((response) => { | |
if(response.ok){ | |
this.setState({data: response.json()}) | |
}else{ | |
console.log(response); | |
} | |
}) | |
.catch(function(error) { | |
console.log(error.message); | |
}); | |
}, | |
render: function() { | |
return ( | |
<div className={"commentBox"}> | |
<div> | |
<div> | |
<input /> | |
</div> | |
<button>Enviar</button> | |
</div> | |
<div> | |
{this.state.data.map((data)=>{ | |
return (<p>{data}</p>); | |
})} | |
</div> | |
</div> | |
); | |
} | |
}); | |
ReactDOM.render( | |
<InputBox />, | |
document.getElementById('contenido') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment