From 4810fd70b59940aabfb27f58dd412a21a366722e Mon Sep 17 00:00:00 2001 From: Dmitri Pisarev Date: Sun, 20 Dec 2020 20:23:17 +0300 Subject: [PATCH] Support server-side rendering --- index.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/index.js b/index.js index 0a98499..a9c9a9e 100644 --- a/index.js +++ b/index.js @@ -12,6 +12,10 @@ import { useTransactionObservation_UNSTABLE } from 'recoil' * `localStorage`. Defaults value is `localStorage`. */ export function recoilPersist(paths = [], config = {}) { + if (typeof window === 'undefined') { + return { RecoilPersist: () => null, updateState: () => {} } + } + const key = config.key || 'recoil-persist' const storage = config.storage || localStorage