format CodeMirror

This commit is contained in:
Abi Raja 2023-11-28 09:49:57 -05:00
parent c3f6f763b4
commit f8772a0515

View File

@ -22,7 +22,9 @@ interface Props {
function CodeMirror({ code, editorTheme, onCodeChange }: Props) { function CodeMirror({ code, editorTheme, onCodeChange }: Props) {
const ref = useRef<HTMLDivElement>(null); const ref = useRef<HTMLDivElement>(null);
const view = useRef<EditorView | null>(null); const view = useRef<EditorView | null>(null);
const editorState = useMemo(() => EditorState.create({ const editorState = useMemo(
() =>
EditorState.create({
extensions: [ extensions: [
history(), history(),
keymap.of([ keymap.of([
@ -43,7 +45,9 @@ function CodeMirror({ code, editorTheme, onCodeChange }: Props) {
} }
}), }),
], ],
}), [editorTheme]); }),
[editorTheme]
);
useEffect(() => { useEffect(() => {
view.current = new EditorView({ view.current = new EditorView({
state: editorState, state: editorState,
@ -67,9 +71,11 @@ function CodeMirror({ code, editorTheme, onCodeChange }: Props) {
}, [code]); }, [code]);
return ( return (
<div className="overflow-x-scroll overflow-y-scroll mx-2 border-[4px] border-black rounded-[20px]" ref={ref} /> <div
className="overflow-x-scroll overflow-y-scroll mx-2 border-[4px] border-black rounded-[20px]"
ref={ref}
/>
); );
} }
export default CodeMirror; export default CodeMirror;