From e79aea15bdc2261c0cc1badb3fa00a3473d5b761 Mon Sep 17 00:00:00 2001 From: Mehdi <56638730+midrizi@users.noreply.github.com> Date: Fri, 4 Aug 2023 23:12:31 +0200 Subject: [PATCH] Fix: Error while converting `null` to `RootStore` (#2479 by @midrizi) [skip ci] * Fix: Error while converting `null` to `RootStore` Fixes the following issue: [mobx-state-tree] Error while converting `null` to `RootStore`: value `null` is not assignable to type: `RootStore` (Value is not a plain object). * Remove null type from restoredState3 --- boilerplate/app/models/helpers/setupRootStore.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/boilerplate/app/models/helpers/setupRootStore.ts b/boilerplate/app/models/helpers/setupRootStore.ts index 634a0ed77..50f2ccf07 100644 --- a/boilerplate/app/models/helpers/setupRootStore.ts +++ b/boilerplate/app/models/helpers/setupRootStore.ts @@ -27,7 +27,7 @@ export async function setupRootStore(rootStore: RootStore) { try { // load the last known state from AsyncStorage - restoredState = (await storage.load(ROOT_STATE_STORAGE_KEY)) as RootStoreSnapshot | null + restoredState = ((await storage.load(ROOT_STATE_STORAGE_KEY)) ?? {}) as RootStoreSnapshot applySnapshot(rootStore, restoredState) } catch (e) { // if there's any problems loading, then inform the dev what happened