Skip to content

Instantly share code, notes, and snippets.

@nomoney4me
Created November 18, 2018 00:40
Show Gist options
  • Select an option

  • Save nomoney4me/9a74990079f31a2eaa4678c0b33cbe03 to your computer and use it in GitHub Desktop.

Select an option

Save nomoney4me/9a74990079f31a2eaa4678c0b33cbe03 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react'
export default class componentName extends Component {
constructor(props) {
super(props);
this.state = {
data: null
}
}
componentDidMount() {
var es = new EventSource('http://localhost:3001/stream')
es.onmessage = (e) => {
this.setState({ data: e.data })
}
}
render() {
return (
<div>
{ this.state.data ? this.state.data : "nothing to show here"}
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment