soyguijarro / react-storage-hooks

React hooks for persistent state
https://npm.im/react-storage-hooks
MIT License
166 stars 18 forks source link

SSR (no window or storage) #1

Closed wKovacs64 closed 5 years ago

wKovacs64 commented 5 years ago

This currently can't be used in a server-side rendered app because localStorage, sessionStorage, and window don't exist.

ReferenceError: localStorage is not defined

Can we add either some mock objects or noops if these are missing?

Thanks!

soyguijarro commented 5 years ago

Hi, thanks for reporting! Can't look into this right now, will try to do it in a couple of weeks.

soyguijarro commented 5 years ago

@wKovacs64 Fixed in version 3.0.0 (already released). I haven't actually tried it in a SSR project but it should work, I added specific tests for this with the environment set to Node.