Skip to content

Commit

Permalink
Deprecated default export and exported named export useMetaTags
Browse files Browse the repository at this point in the history
  • Loading branch information
lordgiotto committed Feb 5, 2024
1 parent afe084a commit e15600d
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ or
## Example

```js
import useMetaTags from 'react-metatags-hook';
import { useMetaTags } from 'react-metatags-hook';

const Component = ({ match }) => {
const {
Expand Down
2 changes: 1 addition & 1 deletion src/generate-static-html.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -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';
2 changes: 1 addition & 1 deletion src/state/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export { default as parseMetaConfig } from './parse';
export { parseMetaConfig } from './parse';
export * from './store';
export * from './helpers';
2 changes: 1 addition & 1 deletion src/state/parse.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import parseMetaConfig from './parse';
import { parseMetaConfig } from './parse';

const metaTagsConfig = {
title: 'A title',
Expand Down
4 changes: 1 addition & 3 deletions src/state/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -111,5 +111,3 @@ const parseMetaConfig = ({
tags,
};
};

export default parseMetaConfig;
2 changes: 1 addition & 1 deletion src/use-meta-tags.spec.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
18 changes: 15 additions & 3 deletions src/use-meta-tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
};

0 comments on commit e15600d

Please sign in to comment.