如何使用 React 创建可运行的代码片段?

Kur*_*eek 2 html javascript css reactjs

我正在关注 React.js 教程 ( https://reactjs.org/tutorial/tutorial.html ) 并想使用 Stackoverflow 的代码片段询问有关它的问题。我已经尝试按照如何创建具有 JSX 支持的 React Stack Snippet的说明进行操作?,但我得到了

Error: {
  "message": "Uncaught ReferenceError: require is not defined",
  "filename": "",
  "lineno": 5,
  "colno": 14
}
Run Code Online (Sandbox Code Playgroud)

我对 React.js 代码片段的尝试如下所示:

Error: {
  "message": "Uncaught ReferenceError: require is not defined",
  "filename": "",
  "lineno": 5,
  "colno": 14
}
Run Code Online (Sandbox Code Playgroud)
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';

class Square extends React.Component {
  render() {
    return (
      <button className="square">
        {/* TODO */}
      </button>
    );
  }
}

class Board extends React.Component {
  renderSquare(i) {
    return <Square />;
  }

  render() {
    const status = 'Next player: X';

    return (
      <div>
        <div className="status">{status}</div>
        <div className="board-row">
          {this.renderSquare(0)}
          {this.renderSquare(1)}
          {this.renderSquare(2)}
        </div>
        <div className="board-row">
          {this.renderSquare(3)}
          {this.renderSquare(4)}
          {this.renderSquare(5)}
        </div>
        <div className="board-row">
          {this.renderSquare(6)}
          {this.renderSquare(7)}
          {this.renderSquare(8)}
        </div>
      </div>
    );
  }
}

class Game extends React.Component {
  render() {
    return (
      <div className="game">
        <div className="game-board">
          <Board />
        </div>
        <div className="game-info">
          <div>{/* status */}</div>
          <ol>{/* TODO */}</ol>
        </div>
      </div>
    );
  }
}

// ========================================

ReactDOM.render(
  <Game />,
  document.getElementById('react')
);
Run Code Online (Sandbox Code Playgroud)
body {
  font: 14px "Century Gothic", Futura, sans-serif;
  margin: 20px;
}

ol, ul {
  padding-left: 30px;
}

.board-row:after {
  clear: both;
  content: "";
  display: table;
}

.status {
  margin-bottom: 10px;
}

.square {
  background: #fff;
  border: 1px solid #999;
  float: left;
  font-size: 24px;
  font-weight: bold;
  line-height: 34px;
  height: 34px;
  margin-right: -1px;
  margin-top: -1px;
  padding: 0;
  text-align: center;
  width: 34px;
}

.square:focus {
  outline: none;
}

.kbd-navigation .square:focus {
  background: #ddd;
}

.game {
  display: flex;
  flex-direction: row;
}

.game-info {
  margin-left: 20px;
}
Run Code Online (Sandbox Code Playgroud)

如何修改此代码段以使其运行?

Jef*_* F. 5

尝试删除导入语句,我认为它们会自动发生。