question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Mentions are not compatible with useEffect

See original GitHub issue

Environment

normal set up, react hooks, following the docs exactly

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:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
fxOnecommented, Jan 8, 2022

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 by draft-js-plugins.

0reactions
fxOnecommented, Jan 13, 2022

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found