File tree Expand file tree Collapse file tree 1 file changed +10
-11
lines changed
Expand file tree Collapse file tree 1 file changed +10
-11
lines changed Original file line number Diff line number Diff line change 11import CodeMirror , { ReactCodeMirrorRef } from '@uiw/react-codemirror' ;
22import { langs } from '@uiw/codemirror-extensions-langs' ;
3- import { useEffect , useRef } from 'react' ;
3+ import { useRef } from 'react' ;
44
55export function Component ( ) {
6- const $edit = useRef < ReactCodeMirrorRef > ( null ) ;
7- useEffect ( ( ) => {
8- console . log ( '$edit:' , $edit ) ;
9- setTimeout ( ( ) => {
10- console . log ( '$edit:view:' , $edit . current ?. view ) ;
11- console . log ( '$edit:state:' , $edit . current ?. state ) ;
12- } , 300 ) ;
13- console . log ( '$edit:' , $edit . current ?. view ) ;
14- } , [ $edit ] ) ;
6+ let $edit = useRef < ReactCodeMirrorRef | null > ( null ) ;
7+ function refCallack ( editor : ReactCodeMirrorRef ) {
8+ if ( ! $edit . current && editor ?. editor && editor ?. state && editor ?. view ) {
9+ // first time we got ref, similar to useEffect
10+ console . log ( editor ) ; // do something with editor
11+ $edit . current = editor ; // store it
12+ }
13+ }
1514 return (
1615 < div >
1716 < CodeMirror
1817 value = { `console.log('hello')` }
1918 theme = "none"
20- ref = { $edit }
19+ ref = { refCallack }
2120 height = "400px"
2221 width = "100%"
2322 style = { { margin : '0 0 23px 0' , flex : 1 } }
You can’t perform that action at this time.
0 commit comments