File tree Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Expand file tree Collapse file tree 1 file changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -38,9 +38,13 @@ function throttle(cb, ms) {
38
38
} ;
39
39
}
40
40
41
- const dispatchStorageEvent = ( key , newValue ) => {
41
+ function isPlainObject ( value ) {
42
+ return Object . prototype . toString . call ( value ) === "[object Object]" ;
43
+ }
44
+
45
+ function dispatchStorageEvent ( key , newValue ) {
42
46
window . dispatchEvent ( new StorageEvent ( "storage" , { key, newValue } ) ) ;
43
- } ;
47
+ }
44
48
45
49
export function useBattery ( ) {
46
50
const [ state , setState ] = React . useState ( {
@@ -910,14 +914,16 @@ export function useObjectState(initialValue) {
910
914
setState ( ( s ) => {
911
915
const newState = arg ( s ) ;
912
916
913
- return {
914
- ...s ,
915
- ...newState ,
916
- } ;
917
+ if ( isPlainObject ( newState ) ) {
918
+ return {
919
+ ...s ,
920
+ ...newState ,
921
+ } ;
922
+ }
917
923
} ) ;
918
924
}
919
925
920
- if ( typeof arg === "object" ) {
926
+ if ( isPlainObject ( arg ) ) {
921
927
setState ( ( s ) => ( {
922
928
...s ,
923
929
...arg ,
You can’t perform that action at this time.
0 commit comments