();
+
+ React.useEffect(() => {
+ const stateFromLocalStorage = localStorage?.getItem('dataGridState');
+ setInitialState(stateFromLocalStorage ? JSON.parse(stateFromLocalStorage) : {});
+ }, []);
+
+ const saveSnapshot = React.useCallback(() => {
+ if (apiRef?.current && localStorage) {
+ const currentState = apiRef.current.exportState();
+ localStorage.setItem('dataGridState', JSON.stringify(currentState));
+ }
+ }, [apiRef]);
+
+ if (!initialState) {
+ return ;
+ }
+
+ return (
+
+
+
+ );
+}
diff --git a/docs/data/data-grid/state/SaveAndRestoreStateInitialState.tsx.preview b/docs/data/data-grid/state/SaveAndRestoreStateInitialState.tsx.preview
new file mode 100644
index 0000000000000..aaea3703c6eab
--- /dev/null
+++ b/docs/data/data-grid/state/SaveAndRestoreStateInitialState.tsx.preview
@@ -0,0 +1,10 @@
+
\ No newline at end of file
diff --git a/docs/data/data-grid/state/state.md b/docs/data/data-grid/state/state.md
index fc6d84fb87cd1..b71d383446fb5 100644
--- a/docs/data/data-grid/state/state.md
+++ b/docs/data/data-grid/state/state.md
@@ -93,6 +93,13 @@ If you restore the page using `initialState` before the data is fetched, the Dat
{{"demo": "RestoreStateInitialState.js", "bg": "inline", "defaultCodeOpen": false}}
+### Save and restore the state from external storage
+
+You can use `apiRef.current.exportState()` to save a snapshot of the state to an external storage (e.g. using `localStorage` or `redux`).
+This way the state can be persisted when refreshing the page or navigating to another page.
+
+{{"demo": "SaveAndRestoreStateInitialState.js", "bg": "inline", "defaultCodeOpen": false}}
+
### Restore the state with apiRef
You can pass the state returned by `apiRef.current.exportState()` to the `apiRef.current.restoreState` method.
diff --git a/docs/scripts/pages/playground/index.tsx b/docs/scripts/pages/playground/index.tsx
new file mode 100644
index 0000000000000..8892bf1b46a8d
--- /dev/null
+++ b/docs/scripts/pages/playground/index.tsx
@@ -0,0 +1,7 @@
+import * as React from 'react';
+
+export default function Playground() {
+ return (
+ A playground for a fast iteration development cycle in isolation outside of git.
+ );
+}