Input Area disappers on source #283
-
I have multiple instances of the react quill, everything works fine except when I add quill-mention, the input area disappears. I found that the 'source' function seems to be responsible for this. Any help with this? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
Hi. What did it for me was:
If after those steps it still doesn't work, try adding By the way, the comment quoted in the 2nd step includes typescript implementation of Quill Mention, which may help as well. |
Beta Was this translation helpful? Give feedback.
-
Just in case, for me wrapping up with |
Beta Was this translation helpful? Give feedback.
-
Has anyone tried to use it by adding a dependency to the useCallback? I need the list of mentions to change. I try using a useCallback or useMemo but as soon as the dependency state changes the editor disappears. |
Beta Was this translation helpful? Give feedback.
-
Adding a dependency to the const RichText = ({
id,
mentions,
...props
}: RichTextProps) => {
const mentionsRef = useRef<Mention[]>([]);
useEffect(() => {
mentionsRef.current = mentions;
}, [mentions]);
return (
<ReactQuill
modules={{
mention: {
allowedChars: /^[A-Za-z\sÅÄÖåäö]*$/,
mentionDenotationChars: ["@"],
source: useCallback(
(
searchTerm: string,
renderList: (arg0: Mention[] | undefined, arg1: string) => void,
mentionChar: string
) => {
let values;
if (mentionChar === "@") {
values = mentionsRef.current;
}
if (searchTerm.length === 0) {
renderList(values, searchTerm);
} else if (values) {
const matches = mentionsRef.current?.filter((item) =>
item.value.toLowerCase().includes(searchTerm.toLowerCase())
);
renderList(matches, searchTerm);
}
},
[]
),
},
}}
onChange={(content) => {
// do something here
}}
{...props}
/>
);
}; |
Beta Was this translation helpful? Give feedback.
Adding a dependency to the
useCallback
, seems to break it. I found the workaround that is, usinguseRef
.