所以我正在尝试使用react-mde,如此处https://github.com/andrerpena/react-mde所示

但是由于某种原因,我的设置中出现错误“未定义不是函数”,我无法弄清楚原因。


import * as React from "react";
import ReactMde from "react-mde";
import ReactDOM from "react-dom";
import * as Showdown from "showdown";
import "react-mde/lib/styles/css/react-mde-all.css";

const converter = new Showdown.Converter({
  tables: true,
  simplifiedAutoLink: true,
  strikethrough: true,
  tasklists: true,
});

function NormEdit() {
  const [value, setValue] = React.useState("**Hello world!!!**");
  const [selectedTab, setSelectedTab] =
    (React.useState < "write") | ("preview" > "write");
  return (
    <div className="container">
      <ReactMde
        value={value}
        onChange={setValue}
        selectedTab={selectedTab}
        onTabChange={setSelectedTab}
        generateMarkdownPreview={(markdown) =>
          Promise.resolve(converter.makeHtml(markdown))
        }
      />
    </div>
  );
}

export default NormEdit;




这是我的代码,下面是发生错误的行


const [selectedTab, setSelectedTab] =
    (React.useState < "write") | ("preview" > "write");



任何帮助将不胜感激=]

最佳答案

您的selectedTab useState需要更像这样:

const [selectedTab, setSelectedTab] = React.useState<"write" | "preview">("write");


这部分<"write" | "preview">看起来像打字稿,并且意味着selectedTab状态只允许是“写”或“预览”的字符串。

07-24 18:06