import { useCookies } from 'react-cookie' ; export const useRememberCookieState = < TValue extends any > ( defaultValue , key = '' ) : [ value : TValue , setValue : ( value : TValue ) => void ] => { const [ cookies , setCookies ] = useCookies ( ) ; const _set = ( value ) => { const save = { _v : value } ; setCookies ( key , save ) ; } ; const _v = ( ( ) => { const _v = cookies [ key ] ; if ( typeof _v === 'undefined' ) { return defaultValue ; } return _v . _v ; } ) ( ) ; return [ _v , _set ] ; } ; type CookieState < TValue extends any > = ( defaultValue : TValue , guid ? : string ) => [ TValue , ( value : TValue ) => void ] ; export const createCookieHooker = < TValue extends any > ( name ) => { const useFunc = ( defaultValue , guid = '' ) => { const [ value , set ] = useRememberCookieState < TValue > ( defaultValue , `${ guid }_${ name }` ) ; return [ value , set ] ; } ; return useFunc ; } ;