CKEditor data does not upload in firestore with TypeError: text is not a function
CKEditor data does not upload in firestore with TypeError: text is not a function
我一直遇到这些代码的错误:
TypeError: text is not a function
const [text, setText] = useState("");
处理提交:
const handleSubmit = (e) => {
e.preventDefault();
try {
const userRef = firestore.collection("announcement").doc();
const ref = userRef.set({
text,
});
text("");
console.log(" saved");
} catch (err) {
console.log(err);
}
};
在函数组件的return里面:
<form onSubmit={handleSubmit}>
<CKEditor
editor={ClassicEditor}
data={text}
onChange={(event, editor1) => {
const data = editor1.getData();
setText(data);
}}
/>
<br />
<br />
<ButtonForm type="submit">Submit</ButtonForm>
</form>
在 handleSubmit
上使用 setText("")
而不是 text("");
我一直遇到这些代码的错误:
TypeError: text is not a function
const [text, setText] = useState("");
处理提交:
const handleSubmit = (e) => {
e.preventDefault();
try {
const userRef = firestore.collection("announcement").doc();
const ref = userRef.set({
text,
});
text("");
console.log(" saved");
} catch (err) {
console.log(err);
}
};
在函数组件的return里面:
<form onSubmit={handleSubmit}>
<CKEditor
editor={ClassicEditor}
data={text}
onChange={(event, editor1) => {
const data = editor1.getData();
setText(data);
}}
/>
<br />
<br />
<ButtonForm type="submit">Submit</ButtonForm>
</form>
在 handleSubmit
setText("")
而不是 text("");