Im trying to implement upload image to server functionality in my react-quill component, and i get errors: quill.getSelection is not a function
My function to handle image uploads looks like this:
const handleUploadImage = () => {
const input = document.createElement("input");
input.setAttribute("type", "file");
input.setAttribute("accept", "image/*");
input.click();
input.onchange = async () => {
const file = input.files[0];
const formData = new FormData();
formData.append("image", file);
const range = quill.getSelection(true);
quill.setSelection(range.index + 1);
const res = await HttpClient().post("/api/blog/images", formData); // API post, returns image location as string e.g. 'http://www.example.com/images/foo.png'
if (res.status === 201) {
quill.deleteText(range.index, 1);
quill.insertEmbed(range.index, "image", res.data);
}
};
};
The problem is that quill, which is a ref, doesnt get the full api, when i console.log quill.current, only a few functions. How do I get the full API?