@@ -283,17 +283,17 @@ CodeMirror allows to serialize editor state to JSON representation with [toJSON]
283
283
284
284
For example, this is how undo history can be saved in the local storage, so that it remains after the page reloads
285
285
286
- ```
287
- import CodeMirror from '@uiw/react-codemirror'
288
- import { historyField } from '@codemirror/commands'
286
+ ``` jsx
287
+ import CodeMirror from ' @uiw/react-codemirror' ;
288
+ import { historyField } from ' @codemirror/commands' ;
289
289
290
290
// When custom fields should be serialized, you can pass them in as an object mapping property names to fields.
291
291
// See [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) documentation for more details
292
- const stateFields = { history: historyField }
292
+ const stateFields = { history: historyField };
293
293
294
294
export function EditorWithInitialState () {
295
- const serializedState = localStorage.getItem('myEditorState')
296
- const value = localStorage.getItem('myValue') || ''
295
+ const serializedState = localStorage .getItem (' myEditorState' );
296
+ const value = localStorage .getItem (' myValue' ) || ' ' ;
297
297
298
298
return (
299
299
< CodeMirror
@@ -307,13 +307,13 @@ export function EditorWithInitialState() {
307
307
: undefined
308
308
}
309
309
onChange= {(value , viewUpdate ) => {
310
- localStorage.setItem('myValue', value)
310
+ localStorage .setItem (' myValue' , value);
311
311
312
- const state = viewUpdate.state.toJSON(stateFields)
313
- localStorage.setItem('myEditorState', JSON.stringify(state))
312
+ const state = viewUpdate .state .toJSON (stateFields);
313
+ localStorage .setItem (' myEditorState' , JSON .stringify (state));
314
314
}}
315
315
/ >
316
- )
316
+ );
317
317
}
318
318
```
319
319
0 commit comments