@@ -12,7 +12,7 @@ import Canvas from "./components/Canvas";
12
12
import Menu from "./components/Menu" ;
13
13
import EraserCursor from "./components/EraserCursor" ;
14
14
import TextEditor from "./components/TextEditor" ;
15
- import { useRecoilValue , useRecoilState } from "recoil" ;
15
+ import { useRecoilValue , useRecoilState , useSetRecoilState } from "recoil" ;
16
16
import {
17
17
eraserState ,
18
18
cursorPosition ,
@@ -21,7 +21,7 @@ import {
21
21
showMenuState ,
22
22
showTextEditor ,
23
23
docState ,
24
- textState ,
24
+ textEditorInput
25
25
} from "./atoms" ;
26
26
27
27
function App ( ) {
@@ -37,7 +37,7 @@ function App() {
37
37
const [ currentCanvas , setCanvas ] = useRecoilState ( canvasState ) ;
38
38
const [ doc , setDoc ] = useRecoilState ( docState ) ;
39
39
const [ provider , setProvider ] = useState ( null ) ;
40
- const [ text , setText ] = useRecoilState ( textState ) ;
40
+ const setTextEditorInput = useSetRecoilState ( textEditorInput ) ;
41
41
const textEditor = useRecoilValue ( showTextEditor ) ;
42
42
43
43
useEffect ( ( ) => {
@@ -47,6 +47,19 @@ function App() {
47
47
setDoc ( _doc ) ;
48
48
}
49
49
} , [ doc ] ) ;
50
+
51
+ useEffect ( ( ) => {
52
+ if ( provider ) {
53
+ const yText = doc . getText ( "text" ) ;
54
+ const observer = ( ) => {
55
+ setTextEditorInput ( yText . toString ( ) ) ;
56
+ } ;
57
+ yText . observe ( observer ) ;
58
+ return ( ) => {
59
+ yText . unobserve ( observer ) ;
60
+ } ;
61
+ }
62
+ } , [ provider , doc ] ) ;
50
63
51
64
useEffect ( ( ) => {
52
65
if ( doc && ! provider ) {
@@ -62,18 +75,6 @@ function App() {
62
75
}
63
76
} , [ doc , provider ] ) ;
64
77
65
- useEffect ( ( ) => {
66
- if ( provider ) {
67
- const yText = doc . getText ( "text" ) ;
68
- const observer = ( ) => {
69
- setText ( yText . toString ( ) ) ;
70
- } ;
71
- yText . observe ( observer ) ;
72
- return ( ) => {
73
- yText . unobserve ( observer ) ;
74
- } ;
75
- }
76
- } , [ provider , doc ] ) ;
77
78
78
79
function toggleMenu ( ) {
79
80
setShowMenu ( ! showMenu ) ;
0 commit comments