Skip to content

Commit

Permalink
Explain accessing local/sync storage directly
Browse files Browse the repository at this point in the history
Add description from #2 about so future readers can find this info quickly.
  • Loading branch information
ssorallen authored Sep 6, 2020
1 parent ef53000 commit 7bace74
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,36 @@ export default () => {
}
```

### Accessing local/sync storage directly

react-redux prefixes storage keys with `"persist:" + config.key`. If code needs to access storage
directly instead of through Redux, it can construct the key and access the APIs like the following:

```js
// Example config passed to `persistReducer`
const key = 'localStorage';
const localStorageConfig = {
key,
storage: localStorage,
}

//

chrome.storage.local.get([`persist:${key}`], (items) => {
const rootParsed = JSON.parse(items['persist:localStorage']);

// Keep in mind that each reducer must be parsed separately
const someReducer = JSON.parse(parsed.someReducer);

// `someReducer` will be the contents of the reducer of that name when last persisted
});
```

Further discussion: [Accessing storage from content_scripts directly (plain JS) #2][5]

[0]: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage
[1]: https://github.com/rt2zz/redux-persist
[2]: https://www.npmjs.com/package/redux-persist-webextension-storage
[3]: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/local
[4]: https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/storage/sync
[5]: https://github.com/ssorallen/redux-persist-webextension-storage/issues/2

0 comments on commit 7bace74

Please sign in to comment.