Skip to content

Commit a3b60c9

Browse files
committed
Add textInput atom
1 parent ac1a01e commit a3b60c9

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

client/src/atoms.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ export const docState = atom({
3838
export const textState = atom({
3939
key: "textState",
4040
default: null
41+
})
42+
43+
export const textEditorInput = atom({
44+
key: "textEditorInput",
45+
default: ''
4146
})

client/src/components/TextEditor.jsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
1-
import { useSetRecoilState, useRecoilValue } from "recoil";
2-
import { showTextEditor, docState, textState } from "../atoms";
1+
import { useSetRecoilState, useRecoilValue, useRecoilState } from "recoil";
2+
import { showTextEditor, docState, textState, textEditorInput } from "../atoms";
33

44
function TextEditor() {
55
const setTextEditorFalse = useSetRecoilState(showTextEditor);
66
const doc = useRecoilValue(docState);
77
const text = useRecoilValue(textState);
8+
const [input, setInput] = useRecoilState(textEditorInput)
89

910
function removeTextEditor() {
1011
setTextEditorFalse(false);
1112
}
1213

1314
function handleChange(event) {
14-
const newText = event.target.value;
15-
const yText = doc.getText('text');
15+
setInput(event.target.value);
16+
if(!doc) return;
17+
const newText = input;
18+
const yText = doc.getText("text");
1619
yText.delete(0, yText.length);
1720
yText.insert(0, newText);
1821
}

0 commit comments

Comments
 (0)