From 71fa51ef58526c9866040f64b35e75d9764d7475 Mon Sep 17 00:00:00 2001 From: toda Date: Mon, 16 May 2022 15:17:22 +0900 Subject: [PATCH] Async getItem function may return null --- src/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/index.ts b/src/index.ts index 45d1871..527cf05 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,7 +3,7 @@ import { AtomEffect } from 'recoil' export interface PersistStorage { setItem(key: string, value: string): void | Promise mergeItem?(key: string, value: string): Promise - getItem(key: string): null | string | Promise + getItem(key: string): null | string | Promise } export interface PersistConfiguration { @@ -78,7 +78,7 @@ export const recoilPersist = ( return parseState(toParse) } if (typeof toParse.then === 'function') { - return toParse.then(parseState) + return toParse.then(state => state === null ? '{}' : state).then(parseState) } return {}