Skip to content

Commit

Permalink
website: update example.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed May 23, 2023
1 parent 7d69894 commit 250cf04
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions www/src/pages/examples/ExampleRef.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import CodeMirror, { ReactCodeMirrorRef } from '@uiw/react-codemirror';
import { langs } from '@uiw/codemirror-extensions-langs';
import { useEffect, useRef } from 'react';
import { useRef } from 'react';

export function Component() {
const $edit = useRef<ReactCodeMirrorRef>(null);
useEffect(() => {
console.log('$edit:', $edit);
setTimeout(() => {
console.log('$edit:view:', $edit.current?.view);
console.log('$edit:state:', $edit.current?.state);
}, 300);
console.log('$edit:', $edit.current?.view);
}, [$edit]);
let $edit = useRef<ReactCodeMirrorRef | null>(null);
function refCallack(editor: ReactCodeMirrorRef) {
if (!$edit.current && editor?.editor && editor?.state && editor?.view) {
// first time we got ref, similar to useEffect
console.log(editor); // do something with editor
$edit.current = editor; // store it
}
}
return (
<div>
<CodeMirror
value={`console.log('hello')`}
theme="none"
ref={$edit}
ref={refCallack}
height="400px"
width="100%"
style={{ margin: '0 0 23px 0', flex: 1 }}
Expand Down

0 comments on commit 250cf04

Please sign in to comment.