React 未在 Codesandbox 中定义,在本地运行良好

React is not defined in Codesandbox, working fine locally

只是想在 Codesandbox 上托管一些示例代码,但是 MyTable.tsx

中的代码
import { FC, useState } from "react";

interface Row {
  id: number;
  content: string;
}

interface Props {
  initialRows: Row[];
}

export const MyTable: FC<Props> = function ({ initialRows }) {
  const [rows, setRows] = useState(initialRows);

  return (
    <table>
      <tbody>
        {rows.map((row, index) => (
          <tr key={`id${row.id}`}>
            <td>{row.content}</td>
            <td>
              <button
                type="button"
                onClick={() => {
                  const newRows = [...rows];
                  newRows.splice(index, 1);
                  setRows(newRows);
                }}
              >
                remove
              </button>
            </td>
          </tr>
        ))}
      </tbody>
    </table>
  );
};

最后是 React is not defined

该代码在 VSCode 中本地运行良好,但我无法弄清楚问题出在哪里。 https://codesandbox.io/s/delete-via-index-ctpes 处的完整 Codesanbox,相关文件是 src/MyTable.tsx。很高兴得到任何提示,谢谢。

您需要添加到 header:

import React, { FC, useState } from "react";