Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. import React from "react";
  2. import Button from "@material-ui/core/Button";
  3. import io from "socket.io-client";
  4.  
  5. var socket = io.connect("wss://fx.glitch.me");
  6.  
  7. const Button1 = () => (
  8. <Button variant="contained" color="primary">
  9. Hello World
  10. </Button>
  11. );
  12.  
  13. export default class App extends React.Component {
  14. handleClick = (e, id) => {
  15. socket.emit("message", "Hi server, how are you?");
  16.  
  17. console.log(id);
  18. };
  19.  
  20. componentDidMount = () => {
  21. socket.on("message", function(message) {
  22. console.log("The server has a message for you: " + message);
  23. });
  24. };
  25. render() {
  26. return (
  27. <div>
  28. <Button
  29. variant="contained"
  30. style={{ margin: 5 }}
  31. onClick={e => this.handleClick(e, "one")}
  32. >
  33. Default
  34. </Button>
  35. <Button
  36. variant="contained"
  37. color="primary"
  38. style={{ margin: 5 }}
  39. onClick={e => this.handleClick(e, "two")}
  40. >
  41. Primary
  42. </Button>
  43. <Button
  44. variant="contained"
  45. color="secondary"
  46. style={{ margin: 5 }}
  47. onClick={e => this.handleClick(e, "three")}
  48. >
  49. Secondary
  50. </Button>
  51. </div>
  52. );
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement