From e996157f43546da7847217bdf81905d662b5dd4c Mon Sep 17 00:00:00 2001 From: radkostanev Date: Tue, 14 Sep 2021 14:42:20 +0300 Subject: [PATCH] chore(treelist): update state localstorage example --- components/treelist/state.md | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/components/treelist/state.md b/components/treelist/state.md index d4a1732901..3d551ae199 100644 --- a/components/treelist/state.md +++ b/components/treelist/state.md @@ -146,7 +146,20 @@ The following example shows one way you can store the TreeList state - through a async Task OnStateInitHandler(TreeListStateEventArgs args) { - args.TreeListState = await LocalStorage.GetItem>(UniqueStorageKey); + try + { + var state = await LocalStorage.GetItem>(UniqueStorageKey); + if (state != null) + { + args.TreeListState = state; + } + + } + catch (InvalidOperationException e) + { + // the JS Interop for the local storage cannot be used during pre-rendering + // so the code above will throw. Once the app initializes, it will work fine + } } async Task OnStateChangedHandler(TreeListStateEventArgs args)