Skip to content

Commit adfaa5a

Browse files
committed
Support more module targets and typo fix
1 parent 0a684a3 commit adfaa5a

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ export function getNamespace(WrapperComponent, WrapperComponentInstance) {
1515
return WrapperComponent.localStorageNamespace(WrapperComponentInstance.props, WrapperComponentInstance.state);
1616
}
1717

18-
console.error('need to define a key');
18+
console.error('Namespace is missing for the wrapped component. Make sure your component has localStorageNamespace present.');
1919
}

src/withLocalStorage.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ function withLocalStorage(WrapperComponent, options) {
88
function localStorageMiddleWare (callback, _this) {
99
const stateObj = pick(_this.state, keysToSync);
1010
const namespace = getNamespace(WrapperComponent, _this);
11-
localStorage.setItem(namespace, JSON.stringify(stateObj));
11+
try {
12+
localStorage.setItem(namespace, JSON.stringify(stateObj));
13+
} catch (e) {
14+
console.error(e);
15+
}
1216
callback.call(_this);
1317
}
1418

webpack.config.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,19 @@ module.exports = {
3030
},
3131

3232
externals: {
33-
react: 'React',
34-
'react-dom': 'ReactDOM',
33+
"react": {
34+
root: 'React',
35+
commonjs2: 'react',
36+
commonjs: 'react',
37+
amd: 'react',
38+
umd: 'react',
39+
},
40+
'react-dom': {
41+
root: 'ReactDOM',
42+
commonjs2: 'react-dom',
43+
commonjs: 'react-dom',
44+
amd: 'react-dom',
45+
umd: 'react-dom'
46+
},
3547
}
3648
}

0 commit comments

Comments
 (0)