Loading State
Loading State
This section described loading a dock layout.
onDidLayoutFromJSON | Invoked after a layout is deserialzied using the fromJSON method.
|
---|---|
fromJSON | Create a component from a serialized object.
|
Load A Layout
To load a layout you should a pass a valid object to fromJSON
. If you try to load an invalid or corrupted layout the dock will throw an Error and the dock will reset gracefully ready
for another attempt with a valid object.
You could load a previously saved layout from local storage for example.
const onReady = (event: DockviewReadyEvent) => {
let success = false;
const mySerializedLayout = localStorage.getItem('my_layout');
if (mySerializedLayout) {
try {
const layout = JSON.parse(mySerializedLayout);
event.api.fromJSON(layout);
success = true;
} catch (err) {
// log the error
}
}
if (!success) {
// perhap load a default layout?
}
};
return <DockviewComponent onReady={onReady}/>;