Closed
Description
My config is pretty simple:
persist('some', storeM, {
blacklist: [],
}).then(() => { ... });
Yet I get this error:
VM1685:1 Uncaught TypeError: Illegal invocation
at eval (eval at callWithPromise (mst-persist.esm.js:42), <anonymous>:1:1)
at callWithPromise (mst-persist.esm.js:42)
at Object.getItem (mst-persist.esm.js:26)
at persist (mst-persist.esm.js:89)
at RootUIWrapper.ComponentWillMount (Root.js:198)
at RootUIWrapper.UNSAFE_componentWillMount (index.js:694)
at callComponentWillMount (react-dom.development.js:13371)
at mountClassInstance (react-dom.development.js:13461)
at updateClassComponent (react-dom.development.js:16986)
at beginWork$1 (react-dom.development.js:18505)
Googled it, and it appears to be the same issue here: https://stackoverflow.com/questions/41126149/using-a-shortcut-function-gives-me-a-illegal-invocation-error
To fix, you can either bind the getItem
/setItem
functions to the localStorage object, or do the equivalent by using a (...args)=>localStorage.XXX(...args)
wrapper function.
For now I am fixing it by globally applying the bind:
window.localStorage.getItem = window.localStorage.getItem.bind(window.localStorage);
window.localStorage.setItem = window.localStorage.setItem.bind(window.localStorage);
However, the library should not require the developer to apply this global binding.