Skip to content

Commit 79ebb43

Browse files
authored
chore(treelist): update state localstorage example (#501)
1 parent 787a01a commit 79ebb43

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

components/treelist/state.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,20 @@ The following example shows one way you can store the TreeList state - through a
146146
147147
async Task OnStateInitHandler(TreeListStateEventArgs<Employee> args)
148148
{
149-
args.TreeListState = await LocalStorage.GetItem<TreeListState<Employee>>(UniqueStorageKey);
149+
try
150+
{
151+
var state = await LocalStorage.GetItem<TreeListState<Employee>>(UniqueStorageKey);
152+
if (state != null)
153+
{
154+
args.TreeListState = state;
155+
}
156+
157+
}
158+
catch (InvalidOperationException e)
159+
{
160+
// the JS Interop for the local storage cannot be used during pre-rendering
161+
// so the code above will throw. Once the app initializes, it will work fine
162+
}
150163
}
151164
152165
async Task OnStateChangedHandler(TreeListStateEventArgs<Employee> args)

0 commit comments

Comments
 (0)