Mentions are not compatible with useEffect
See original GitHub issueEnvironment
normal set up, react hooks, following the docs exactly
- @draft-js-plugins/editor version: 4.1.
- plugin name and version: mention 5.1
Description
Reproducible Demo
Here’s an example that uses the mentions plugin - this will help get you started The link to the working example in the template is broken
If you need a working example, if you wouldn’t mind sharing a fixed version of the above link, it would save me a lot of time. Otherwise I think this is a known feature of mentions so I’m not sure if it’s necessary.
The following useEffect logic I am using overwrites the mention plugin is the following.
Each one overwrites the mention plugin. I feel like the incompatibility with useEffect should be a primary focus in the docs, or, even more ideally, the plugin should be compatible with this hook
useEffect(() => {
if(props.focusOnMount){
// timeout is required otherwise it overwrites the mentions plugin
editor.current.focus()
}
}, [])
// this hook is used to update the editor state from realtime events
useEffect(() => {
let es = getEditorStateFromRaw(props.content))
// timeout is required otherwise it overwrites the mentions plugin
setEditorState(es)
}, [props.content])
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
How To Fix The "useEffect must not return anything besides a ...
That is because the callback itself is returning a promise which is incompatible with useEffect . The Solution. The fix here is actually...
Read more >Why does useEffect React Hook not work properly with ...
Long story short, Fullcalendar has an api that refetches any events from a given source . In my case, my source is state.events...
Read more >The last guide to the useEffect Hook you'll ever need
Understanding how the useEffect Hook works, and why it requires a wholesale shift in mindset, is essential to writing modern React code.
Read more >Using the Effect Hook - React
If you're familiar with React class lifecycle methods, you can think of useEffect Hook as componentDidMount , componentDidUpdate , and componentWillUnmount ...
Read more >Why doesn't React.useEffect run on React server-side renders ...
Those 3 methods don't run during a server-side render (SSR) of a React class component, so it stands to reason that useEffect doesn't...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for reporting the broken link. It looks like codesandbox removes templates after a while.
I will add a note to the FAQ page that if you create a new
EditorState
it will not have the decorators which are added bydraft-js-plugins
.I’ll reopen this issue as I want to add some notes to the FAQ to make the issue clear and provide some links to the solutions