Closed gurleensethi closed 3 years ago
I'm pretty sure that example is not complete. As it works just fine in the demo with the same code.
https://codesandbox.io/s/still-sea-pypbe?file=/src/App.tsx Take a look here. All works fine.
I'm getting the same error in my app when I pass in options, like:
<SimpleMDE
value={value}
onChange={onChange}
options={{ hideIcons: ["image", "side-by-side", "fullscreen", "guide"], status: false, minHeight: "100px" }}
/>
When I remove options, it doesn't crash.
So, after looking into this a bit more, if I pass in my options as a constant I no longer get the error.
My error was likely caused by the useEffect
dependency array here -> https://github.com/RIP21/react-simplemde-editor/blob/6b712e51f1e64cf9db2be1776db3e405ba09d99c/src/SimpleMdeReact.tsx#L197
If a new options object ref is passed in on render, the useEffect
is triggered and setEditor
gets called again, recreating the instance.
@markthiessen it's intentional and there is no way to get rid of that if I want options to change. Unfortunately, there is no .setOption
or smth similar in MDE API, so only recreation is an option to change them reactively.
https://github.com/RIP21/react-simplemde-editor#options
The fact that options shall be memoized and why is described here.
So, meaning, there is nothing I can do nor change. And it's just integration got improved since old version and became more correct to what one can expect from it. The only way to fix this that I can see is to save the cursor position of the old instance and then when a new one is getting created to set it back into a new instance, but I guess there will be a lot of issues with that and I don't think it worth it as it is fixable by a simple memo.
@RIP21 for sure -- in my scenario ensuring the options are constant is a better approach anyway. It just took me a bit longer than expected to migrate from 4.x.x -> 5.0.0 as I didn't see anything standing out from the release notes, so I needed to dive in to find out why it was erroring. You have good examples in the README, so I wouldn't expect new users to run into it, more just during upgrades.
@markthiessen yup. Sorry for that. That's why I slightly changed a readme after multiple people encountered that, to ensure people will note that. Even old users. Thanks for these issues :) It helps improve experience for next users :)
Library Version:
5.0.1
I am using this component in the below structure:
Whenever I start typing in the editor, the application crashes and below is the stack trace that appears.
PS: This was working fine in
4.1.5