Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent onChange handler from being fired when value property is changed from the outside #456

Merged
merged 1 commit into from
Feb 9, 2023

Conversation

11bit
Copy link
Contributor

@11bit 11bit commented Feb 9, 2023

Do not fire onChange handler when codemirror's value is changed from outside (this is how ordinary inputs work). Usually it doesn't matter but when CM is used with async apis it can lead to cycling changes of text

Consider the following example (sandbox):

export default function App() {
  const [v, sv] = useState("test");
  return (
    <>
      <input
        value={v}
        onChange={(e) => {
          console.log("input: onChange");
          sv(e.target.value);
        }}
      />
      <CodeMirror
        value={v}
        onChange={(x) => {
          console.log("CodeMirror: onChange");
          sv(x);
        }}
      />
    </>
  );
}

Here input field and CodeMirror are bound to one state.

  1. When I edit CodeMirror, the input's onChange has not fired and the console output is
> CodeMirror: onChange
  1. But when I edit input, both onChange handlers fire:
> input: onChange
> CodeMirror: onChange

@11bit
Copy link
Contributor Author

11bit commented Feb 9, 2023

Might fix #443 and #310?

@jaywcjlove jaywcjlove merged commit 7637bff into uiwjs:master Feb 9, 2023
jaywcjlove added a commit that referenced this pull request Feb 9, 2023
github-actions bot pushed a commit that referenced this pull request Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants