I have created a component for RichText with ReactQuill and i am implementing mentions but when i type @ in textbox mentions not working i tried puting dependency in useMemo but the textbox disapears
How can i make this code work so when i type @ it shows the list of people?
Below please find the code which i made
const RichText = (props) => {
const [people, setPeople] = useState([]);
const reactQuillRef = React.useRef(null);
useEffect(() => {
setPeople(props.getPeople)
}, []);
const modules = useMemo(
() => ({
toolbar: [
[{ font: [] }],
[{ size: ["small", false, "large", "huge"] }],
["bold", "italic", "underline", "strike", "blockquote"],
[{ list: "ordered" }, { list: "bullet" }],
[{ align: [] }],
[{ color: [] }, { background: [] }],
["image"],
["clean"],
],
mention: {
allowedChars: /^[A-Za-z\sÅÄÖåäö]*$/,
mentionDenotationChars: ["@"],
spaceAfterInsert: true,
source: (searchTerm, renderList, mentionChar) => {
let values;
if (mentionChar === "@") {
values = people;
}
if (searchTerm.length === 0) {
renderList(values, searchTerm);
} else {
const matches = [];
for (let i = 0; i < values.length; i++)
if (
~values[i].value.toLowerCase().indexOf(searchTerm.toLowerCase())
)
matches.push(values[i]);
renderList(matches, searchTerm);
}
},
},
}),
[]
);
return (
<ReactQuill
defaultValue={props.defaultValue || ""}
value={props.value || ""}
theme="snow"
ref={reactQuillRef}
placeholder={props.placeholder}
className={`note_input`}
formats={formats}
modules={modules}
onChange={(content, delta, source, editor) => {
props.setValue(content, delta, source, editor);
}}
/>
);
};
export default RichText;