import React from 'react' ; function useStickyState < T > ( defaultValue , key ) { const [ value , setValue ] = React . useState < T > ( ( ) => { const stickyValue = window . localStorage . getItem ( key ) ; return stickyValue !== null ? JSON . parse ( stickyValue ) : defaultValue ; } ) ; React . useEffect ( ( ) => { window . localStorage . setItem ( key , JSON . stringify ( value ) ) ; } , [ key , value ] ) ; return [ value , setValue ] ; } export default useStickyState ;