onChange function is cached
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 201
- Avg merge
- 12m
- Merged PRs (30d)
- 1
Description
The onChange prop function of the MDEditor component is cached (due to the useReducer), and thus data passed is taken as closure, not updating when component re-renders.
For example, for this code
const [data, setData] = useState({text: "", number:0})
<MDEditor
onChange={(text) => setData({...data, text});
// ....
/>
Problem happens if I update number --> setData({...data, number: 5})
When MDEditor changes, number is reset to 0, because onChange function is cached with data being {text:"", value: 0}
I hope I have made myself clear. If not I can push a full component example of this problem.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the MDEditor component and trace how useReducer stores or invokes the onChange prop. Reproduce the issue with the provided data and number state example, then verify that changing the editor no longer resets the updated number value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100