Skip to content

Commit

Permalink
fix: Fix value props controlled issue. #199
Browse files Browse the repository at this point in the history
  • Loading branch information
jaywcjlove committed Oct 14, 2021
1 parent 24eb08b commit 29a3145
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 5 additions & 3 deletions src/useCodeMirror.ts
Expand Up @@ -104,9 +104,11 @@ export function useCodeMirror(props: UseCodeMirror) {
useEffect(() => {
if (view) {
const currentValue = view.state.doc.toString();
view.dispatch({
changes: { from: 0, to: currentValue.length, insert: value || '' },
});
if (value !== currentValue) {
view.dispatch({
changes: { from: 0, to: currentValue.length, insert: value || '' },
});
}
}
}, [value, view]);

Expand Down
4 changes: 1 addition & 3 deletions website/App.tsx
Expand Up @@ -193,9 +193,7 @@ export default function App() {
autoFocus={autofocus}
className={styles.codemirror}
placeholder={placeholder}
onChange={(value) => {
// console.log('value:', value);
}}
onChange={(value) => setCode(value)}
style={{
maxWidth: '995px',
margin: '-18px auto 0 auto',
Expand Down

0 comments on commit 29a3145

Please sign in to comment.