Created
November 18, 2018 00:40
-
-
Save nomoney4me/9a74990079f31a2eaa4678c0b33cbe03 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
| 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