Moorper Wiki

我等采石之人,当心怀建造大教堂之愿景。

用户工具

站点工具


blog:nextjs:using-react-ace-in-nextjs

在 Next.js 中使用 React-Ace

安装 react-ace

npm install --save react-ace ace-builds

定义 AceEditor 组件

"use client";
 
import React from "react";
import dynamic from "next/dynamic";
 
const AceEditor = dynamic(
  async () => {
    const ace = await import("react-ace");
    await import("ace-builds/src-noconflict/mode-java");
    await import("ace-builds/src-noconflict/theme-github");
    await import("ace-builds/src-noconflict/ext-language_tools");
    return ace;
  },
  { ssr: false }
);

使用组件

export default function Home() {
  function onChange(newValue: string) {
    console.log("change", newValue);
  }
  return (
    <AceEditor
      mode="java"
      theme="github"
      onChange={onChange}
      name="UNIQUE_ID_OF_DIV"
      width="100%"
      editorProps={{ $blockScrolling: true }}
    />
  );
}
blog/nextjs/using-react-ace-in-nextjs.txt · 最后更改: Where.Liu

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki