Skip to content

Commit bc01454

Browse files
committed
Fix
1 parent a3b60c9 commit bc01454

File tree

2 files changed

+16
-19
lines changed

2 files changed

+16
-19
lines changed

client/src/App.jsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import Canvas from "./components/Canvas";
1212
import Menu from "./components/Menu";
1313
import EraserCursor from "./components/EraserCursor";
1414
import TextEditor from "./components/TextEditor";
15-
import { useRecoilValue, useRecoilState } from "recoil";
15+
import { useRecoilValue, useRecoilState, useSetRecoilState } from "recoil";
1616
import {
1717
eraserState,
1818
cursorPosition,
@@ -21,7 +21,7 @@ import {
2121
showMenuState,
2222
showTextEditor,
2323
docState,
24-
textState,
24+
textEditorInput
2525
} from "./atoms";
2626

2727
function App() {
@@ -37,7 +37,7 @@ function App() {
3737
const [currentCanvas, setCanvas] = useRecoilState(canvasState);
3838
const [doc, setDoc] = useRecoilState(docState);
3939
const [provider, setProvider] = useState(null);
40-
const [text, setText] = useRecoilState(textState);
40+
const setTextEditorInput = useSetRecoilState(textEditorInput);
4141
const textEditor = useRecoilValue(showTextEditor);
4242

4343
useEffect(() => {
@@ -47,6 +47,19 @@ function App() {
4747
setDoc(_doc);
4848
}
4949
}, [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]);
5063

5164
useEffect(() => {
5265
if (doc && !provider) {
@@ -62,18 +75,6 @@ function App() {
6275
}
6376
}, [doc, provider]);
6477

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]);
7778

7879
function toggleMenu() {
7980
setShowMenu(!showMenu);

client/src/atoms.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ export const docState = atom({
3535
default: null
3636
})
3737

38-
export const textState = atom({
39-
key: "textState",
40-
default: null
41-
})
4238

4339
export const textEditorInput = atom({
4440
key: "textEditorInput",

0 commit comments

Comments
 (0)