You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core/README.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -277,6 +277,46 @@ export default function App() {
277
277
}
278
278
```
279
279
280
+
## Use `initialState` to restore state from JSON-serialized representation
281
+
282
+
CodeMirror allows to serialize editor state to JSON representation with [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) function for persistency or other needs. This JSON representation can be later used to recreate ReactCodeMirror component with the same internal state.
283
+
284
+
For example, this is how undo history can be saved in the local storage, so that it remains after the page reloads
285
+
286
+
```
287
+
import CodeMirror from '@uiw/react-codemirror'
288
+
import { historyField } from '@codemirror/commands'
289
+
290
+
// When custom fields should be serialized, you can pass them in as an object mapping property names to fields.
291
+
// See [toJSON](https://codemirror.net/docs/ref/#state.EditorState.toJSON) documentation for more details
0 commit comments