uiwjs / uiwjs/react-md-editor

onChange function is cached

Open
#297 6 comments 1 reaction 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.