Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. class MyComponent {
  2. componentDidMount() {
  3. this.props.webSocket.on('myEvent', componentDidReceiveEvent)
  4. }
  5.  
  6. componentWillUnmount() {
  7. this.props.webSocket.off('myEvent', componentDidReceiveEvent)
  8. }
  9.  
  10. // is this even method style valid syntax?
  11. componentDidReceiveEvent = limit((evt) => {
  12. this.state.setState((prev, props) => {
  13. return {
  14. ...prev,
  15. inboundEvents: [...prev.events, evt]
  16. };
  17. });
  18. })
  19.  
  20. render() {
  21. return <div>
  22. this.state.events.map(e => <MyNode key={evt.id} />)
  23. </div>
  24. }
  25. }
  26.  
  27. MyComponent.propTypes = {
  28. id: React.PropTypes.string,
  29. webSocket: React.PropTypes.oneOfType([
  30. React.PropTypes.bool,
  31. React.PropTypes.object,
  32. ]),
  33. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement