Skip to content

Commit

Permalink
perf: memoize the extensions in code editor to reduce expensive calcu…
Browse files Browse the repository at this point in the history
…lations (#441)
  • Loading branch information
shanpriyan committed May 21, 2023
1 parent 33f45d3 commit c121967
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/playground/components/CodeEditor.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useMemo } from "react";
import CodeMirror from "@uiw/react-codemirror";
import { history } from "@codemirror/history";
import { bracketMatching } from "@codemirror/matchbrackets";
Expand All @@ -9,20 +9,22 @@ import { Linter as ESLint } from "../node_modules/eslint/lib/linter/";
import "../scss/editor.scss";

export default function CodeEditor({ codeValue, onUpdate, eslintOptions }) {
const extensions = useMemo(() => [
history(),
bracketMatching(),
linter(esLint(new ESLint(), eslintOptions), { delay: 0 }),
javascript(),
ESLintPlaygroundTheme,
ESLintPlaygroundHighlightStyle
], [eslintOptions]);

return (
<CodeMirror
value={codeValue}
minWidth="100%"
height="100%"
extensions={
[
history(),
bracketMatching(),
linter(esLint(new ESLint(), eslintOptions), { delay: 0 }),
javascript(),
ESLintPlaygroundTheme,
ESLintPlaygroundHighlightStyle
]
extensions
}
onChange={value => {
onUpdate(value);
Expand Down

0 comments on commit c121967

Please sign in to comment.