pre-round.component.jsx 787 B

1234567891011121314151617181920212223242526272829303132333435
  1. import React from "react";
  2. class PreRound extends React.Component {
  3. constructor(props) {
  4. super(props);
  5. this.textareaRef = React.createRef();
  6. }
  7. copyGameId() {
  8. const { current } = this.textareaRef;
  9. current.select();
  10. document.execCommand("copy");
  11. }
  12. render() {
  13. const { gameId, playerName, onStart } = this.props;
  14. return (
  15. <div>
  16. <p>Playing as {playerName}</p>
  17. <p>
  18. Game Code: {gameId} <button onClick={() => this.copyGameId()}>Copy</button>
  19. </p>
  20. <button onClick={onStart}>Start Game</button>
  21. <textarea
  22. ref={this.textareaRef}
  23. style={{ position: "absolute", top: "-1000px" }}
  24. value={gameId}
  25. />
  26. </div>
  27. );
  28. }
  29. }
  30. export default PreRound;