@@ -791,72 +791,6 @@ export function useList(defaultList = []) {
791791 return [ list , { set, push, removeAt, insertAt, updateAt, clear } ] ;
792792}
793793
794- const dispatchStorageEvent = ( key , newValue ) => {
795- window . dispatchEvent ( new StorageEvent ( "storage" , { key, newValue } ) ) ;
796- } ;
797-
798- const setLocalStorageItem = ( key , value ) => {
799- const stringifiedValue = JSON . stringify ( value ) ;
800- window . localStorage . setItem ( key , stringifiedValue ) ;
801- dispatchStorageEvent ( key , stringifiedValue ) ;
802- } ;
803-
804- const removeLocalStorageItem = ( key ) => {
805- window . localStorage . removeItem ( key ) ;
806- dispatchStorageEvent ( key , null ) ;
807- } ;
808-
809- const getLocalStorageItem = ( key ) => {
810- return window . localStorage . getItem ( key ) ;
811- } ;
812-
813- const useLocalStorageSubscribe = ( callback ) => {
814- window . addEventListener ( "storage" , callback ) ;
815- return ( ) => window . removeEventListener ( "storage" , callback ) ;
816- } ;
817-
818- const getLocalStorageServerSnapshot = ( ) => {
819- throw Error ( "useLocalStorage is a client-only hook" ) ;
820- } ;
821-
822- export function useLocalStorage ( key , initialValue ) {
823- const getSnapshot = ( ) => getLocalStorageItem ( key ) ;
824-
825- const store = React . useSyncExternalStore (
826- useLocalStorageSubscribe ,
827- getSnapshot ,
828- getLocalStorageServerSnapshot
829- ) ;
830-
831- const setState = React . useCallback (
832- ( v ) => {
833- try {
834- const nextState = typeof v === "function" ? v ( JSON . parse ( store ) ) : v ;
835-
836- if ( nextState === undefined || nextState === null ) {
837- removeLocalStorageItem ( key ) ;
838- } else {
839- setLocalStorageItem ( key , nextState ) ;
840- }
841- } catch ( e ) {
842- console . warn ( e ) ;
843- }
844- } ,
845- [ key , store ]
846- ) ;
847-
848- React . useEffect ( ( ) => {
849- if (
850- getLocalStorageItem ( key ) === null &&
851- typeof initialValue !== "undefined"
852- ) {
853- setLocalStorageItem ( key , initialValue ) ;
854- }
855- } , [ key , initialValue ] ) ;
856-
857- return [ store ? JSON . parse ( store ) : initialValue , setState ] ;
858- }
859-
860794export function useLogger ( name , ...rest ) {
861795 const initialRenderRef = React . useRef ( true ) ;
862796
0 commit comments