From e15600d9bf59e9579037e8397d4d020c96efee98 Mon Sep 17 00:00:00 2001 From: Lorenzo Zottar Date: Mon, 5 Feb 2024 01:11:39 +0100 Subject: [PATCH] Deprecated default export and exported named export `useMetaTags` --- README.md | 2 +- src/generate-static-html.spec.tsx | 2 +- src/index.ts | 2 +- src/state/index.ts | 2 +- src/state/parse.spec.ts | 2 +- src/state/parse.ts | 4 +--- src/use-meta-tags.spec.ts | 2 +- src/use-meta-tags.ts | 18 +++++++++++++++--- 8 files changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 1405b2c..eb4ebdf 100644 --- a/README.md +++ b/README.md @@ -40,7 +40,7 @@ or ## Example ```js -import useMetaTags from 'react-metatags-hook'; +import { useMetaTags } from 'react-metatags-hook'; const Component = ({ match }) => { const { diff --git a/src/generate-static-html.spec.tsx b/src/generate-static-html.spec.tsx index 9d9c340..e6750eb 100644 --- a/src/generate-static-html.spec.tsx +++ b/src/generate-static-html.spec.tsx @@ -4,7 +4,7 @@ import React from 'react'; import ReactDOMServer from 'react-dom/server'; -import useMetaTags from './use-meta-tags'; +import { useMetaTags } from './use-meta-tags'; import { generateStaticHtml, resetMetaTags } from './generate-static-html'; diff --git a/src/index.ts b/src/index.ts index ce807c3..3a6158a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,3 @@ -export { default } from './use-meta-tags'; +export { default, useMetaTags } from './use-meta-tags'; export { generateStaticHtml, resetMetaTags } from './generate-static-html'; export type { MetaTag, LinkTag, MetaTagsConfig } from './types'; diff --git a/src/state/index.ts b/src/state/index.ts index a18c9fa..97d0fe8 100644 --- a/src/state/index.ts +++ b/src/state/index.ts @@ -1,3 +1,3 @@ -export { default as parseMetaConfig } from './parse'; +export { parseMetaConfig } from './parse'; export * from './store'; export * from './helpers'; diff --git a/src/state/parse.spec.ts b/src/state/parse.spec.ts index bd71281..fa27eae 100644 --- a/src/state/parse.spec.ts +++ b/src/state/parse.spec.ts @@ -1,4 +1,4 @@ -import parseMetaConfig from './parse'; +import { parseMetaConfig } from './parse'; const metaTagsConfig = { title: 'A title', diff --git a/src/state/parse.ts b/src/state/parse.ts index 76d722b..0276eb0 100644 --- a/src/state/parse.ts +++ b/src/state/parse.ts @@ -45,7 +45,7 @@ const createInternalMeta = createInternalTag('meta'); const createInternalLink = createInternalTag('link'); // Transforms the hook's input config into the internal metas model -const parseMetaConfig = ({ +export const parseMetaConfig = ({ title, description, lang, @@ -111,5 +111,3 @@ const parseMetaConfig = ({ tags, }; }; - -export default parseMetaConfig; diff --git a/src/use-meta-tags.spec.ts b/src/use-meta-tags.spec.ts index 998baf1..d84a08c 100644 --- a/src/use-meta-tags.spec.ts +++ b/src/use-meta-tags.spec.ts @@ -1,6 +1,6 @@ import { renderHook } from '@testing-library/react'; import { wait } from './helpers/patience'; -import useMetaTags from './use-meta-tags'; +import { useMetaTags } from './use-meta-tags'; const queryHeadSelectorAttribute = (selector: string, attribute: string) => { const element = document.head.querySelector(selector); diff --git a/src/use-meta-tags.ts b/src/use-meta-tags.ts index eae8251..a846e49 100644 --- a/src/use-meta-tags.ts +++ b/src/use-meta-tags.ts @@ -19,7 +19,10 @@ metaTagsStore.subscribe((metas) => updateDom(metas, 50)); // definitions in the registered "instance" in the store // - When a component is unmounted, the instance is deregistered from the store, and its // meta tags are removed from the result of the final merge -const useMetaTags = (config: MetaTagsConfig, dependsOn: unknown[]) => { +export const useMetaTags = ( + config: MetaTagsConfig, + dependencies: unknown[] +) => { const hookInstanceId = useRef(Symbol()); const hookInstanceTs = useRef(Date.now()); // NOTE: When running on the server, effects doesn't run, so here @@ -48,7 +51,16 @@ const useMetaTags = (config: MetaTagsConfig, dependsOn: unknown[]) => { metaTagsStore.setInstanceMetaTags(hookInstanceId.current, newMetaTagsModel); // NOTE: we want to regenerate the meta tags only when the explicit dependencies change // eslint-disable-next-line react-hooks/exhaustive-deps - }, [dependsOn]); + }, [dependencies]); }; -export default useMetaTags; +/** + * @deprecated Do not use the default export from 'react-metatags-hook', it will be removed in a future release. + * + * Please use the named export `useMetaTags`. + * + * e.g. `import { useMetaTags } from 'react-metatags-hook'` + */ +export default (config: MetaTagsConfig, dependencies: unknown[]) => { + useMetaTags(config, dependencies); +};