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) {
3838 } ;
3939}
4040
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 ) {
4246 window . dispatchEvent ( new StorageEvent ( "storage" , { key, newValue } ) ) ;
43- } ;
47+ }
4448
4549export function useBattery ( ) {
4650 const [ state , setState ] = React . useState ( {
@@ -910,14 +914,16 @@ export function useObjectState(initialValue) {
910914 setState ( ( s ) => {
911915 const newState = arg ( s ) ;
912916
913- return {
914- ...s ,
915- ...newState ,
916- } ;
917+ if ( isPlainObject ( newState ) ) {
918+ return {
919+ ...s ,
920+ ...newState ,
921+ } ;
922+ }
917923 } ) ;
918924 }
919925
920- if ( typeof arg === "object" ) {
926+ if ( isPlainObject ( arg ) ) {
921927 setState ( ( s ) => ( {
922928 ...s ,
923929 ...arg ,
You can’t perform that action at this time.
0 commit comments