Comments (13)
Hi,
I ran into the same issue: I think it is realted to componentDidUpdate
this part
if (
!this.state.keyChange &&
this.props.value !== this.state.value && // This is somehow fixes moving cursor for controlled case
this.props.value !== prevProps.value // This one fixes no value change for uncontrolled input. If it's uncontrolled prevProps will be the same
) {
this.simpleMde!.value(this.props.value || "");
}
the state is not correctly updated when props change.
A simple trick solved the issue: I provided a key
attribute with a unique id. Thats makes sure the component is rerendered on props change (I think):
<SimpleMDEReact key={unique_id} value={my_value} onChange={value => onChange} />
from react-simplemde-editor.
This bug depends if the component is controlled or uncontrolled and any solutions should test both cases.
I'm using it as a controlled component and fixed the issue by removing all references to state, since it's not required. I'll try creating a PR that handles both cases.
from react-simplemde-editor.
Hey, @fabriceci thanks for a filled issue.
Can you please make a reproduction using codesandbox.io? Because it's really hard to get what's the issue from the screenshot and this code.
Repro will make it way easier for me to investigate the bug.
from react-simplemde-editor.
Yes of course: here is the codesandbox
- Click on Article 1 , then Article 2 and then Article 1. You will see the desc value will disappear (value of article 2)
- Click on Article 2, then Article 1 then Article 2. You will see the desc value will be the value of Article 1 desc.
As you can see here, the value is updated in the component but not displayed properly.
from react-simplemde-editor.
@fabriceci still had no time to take a look at this one. Hopefully next weekend will investigate it further.
from react-simplemde-editor.
@RIP21 Thank you! I regret not to be able to do more.
from react-simplemde-editor.
Any update?
from react-simplemde-editor.
@haench yes. If you change key
prop it forces component to remount from scratch. It's one of the recommended ways of hard reloading components.
I don't know whether I will have time to fix that. Hopefully soon :( Sorry guys, I have life and a lot of work at Revolut and I just don't have any time now for investigating this particular issue.
from react-simplemde-editor.
Hi
i have a similar issue when I set the value to be empty from extraKeys it will break after the first time.
Here is an example
https://codesandbox.io/s/stoic-wright-tn4l7?fontsize=14&hidenavigation=1&theme=dark
Type something and hit enter... the editor will empty out the field. Now type something again and hit enter and you will see nothing happens
from react-simplemde-editor.
it seems this line in componentDidUpdate is the problem:
this.props.value !== prevProps.value
can we remove this?
from react-simplemde-editor.
from react-simplemde-editor.
actually my codesandbox was not on the latest version... at the latest version it works fine
https://codesandbox.io/s/stoic-wright-tn4l7?fontsize=14&hidenavigation=1&theme=dark
from react-simplemde-editor.
This one is I'm sure is sorted by the latest changes I did in version 5.0.0
. Please check it out! It's totally rewritten and uses hooks now.
Mind breaking changes!
from react-simplemde-editor.
Related Issues (20)
- Not working internal link in README.md HOT 2
- Custom toolbar button to open a separate React component (or any kind of div input from where I can accept input) HOT 3
- How can I disable markdown AutoComplete feature? HOT 1
- lost focus when using onChange with nextjs HOT 7
- lineNumbers option prevents backspace of empty line on Mobile HOT 2
- TypeError `_react.useMemo` is not a function HOT 3
- how to make this RTL ? HOT 7
- Cursor randomly jumps before first character when typing HOT 1
- can't use options when use getCodemirrorInstance to change state HOT 1
- window is not defined HOT 3
- Preview not working (showing undefined) HOT 5
- You may need an additional loader to handle the result of these loaders. HOT 4
- toolbar does not display on MacOS HOT 2
- Enforce maxLength attribute HOT 3
- Editor fetches assets from external sources HOT 1
- Multiline Code Block Highlighting in Edit Mode HOT 1
- Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()? HOT 2
- has fetching error with react query HOT 3
- How to add thin blue border upon selecting the editor?
- Tailwind Reset HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-simplemde-editor.