import { useRef , useMemo , useEffect , MutableRefObject } from 'react' ; import { MetaTagsConfig , MetaTagModel } from './types' ; import { parseMetaConfig , subscribeToStore , addMetasToStore , removeMetasFromStore , } from './state' ; import { updateDom } from './render/dom' ; subscribeToStore ( ( metas ) => updateDom ( metas , 50 ) ) ; const useMetaTags = ( config , dependsOn ? ) => { const instanceConfig = useRef < MetaTagModel > ( ) ; const metas = useMemo ( ( ) => parseMetaConfig ( config ) , dependsOn ) ; useEffect ( ( ) => { return ( ) => { instanceConfig . current && removeMetasFromStore ( instanceConfig as MutableRefObject < MetaTagModel > ) ; } ; } , [ ] ) ; if ( instanceConfig . current !== metas ) { instanceConfig . current = metas ; instanceConfig . current && addMetasToStore ( instanceConfig as MutableRefObject < MetaTagModel > ) ; } } ; export default useMetaTags ;