Skip to content

Instantly share code, notes, and snippets.

@mvanlonden
Created August 27, 2017 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mvanlonden/38ddd1c1da5c35628bbc7822a60fe77f to your computer and use it in GitHub Desktop.
Save mvanlonden/38ddd1c1da5c35628bbc7822a60fe77f to your computer and use it in GitHub Desktop.
Combines prender.cloud and redux-persist to rehydrate your redux state. Use as your redux-persist storage.
import storage from 'redux-persist/es/storage'
const isPrerendering = window.prerenderCloudIsServerSideRendering
export default {
getItem: (key, cb) => {
storage.getItem(key, (err, item) => {
if (err) {
return cb(err)
}
if (item) {
return storage.getItem(key, cb)
}
cb(null, window.__PRELOADED_STATE__)
})
},
setItem: (key, item, cb) => {
if (isPrerendering) {
window.__PRELOADED_STATE__ = item
return cb(null)
}
return storage.setItem(key, item, cb)
},
removeItem: storage.removeItem
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment