uiwjs / uiwjs/react-codemirror
onChange handler should not fire when props change
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.3k
- Forks
- 161
- PR merge metrics
- No merged PRs in 30d
Description
Hi, I am having an issue when trying to update some props from elsewhere in the app, that impact the value prop for CodeMirror. See the code below. There is a rather lengthy discussion on another wrapper here (https://github.com/scniro/react-codemirror2/issues/29) that somewhat describes this issue. Wondering if you had a clean work around, or way we can handle this in the component vs outside?
const Test = () => {
const [state, setState] = useState({
test:"value",
editorValue:"Placeholder"
})
const changeState = () => {
setState({test:"updated value", editorValue:"Updated Placeholder"})
}
return (
<>
<button onClick={changeState}>Change State</button>
<CodeMirror
value={state.editorValue}
height="75vh"
extensions={[xml({ jsx: true })]}
onChange={(value, viewUpdate) => {
setState({...state, editorValue: value )
}}
/>
<div>{JSON.stringify(state)}</div>
</>
)
}
export default Test
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
No repository file or test is named. Start by reproducing the supplied React example with CodeMirror's value prop and onChange handler, then trace the component's prop-update path; done means external prop changes update the editor without firing onChange unexpectedly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100