Skip to content

Commit

Permalink
chore: renamed Portal prop key to name, to avoid react warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Dec 12, 2020
1 parent 8e68847 commit bf6cf1e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/components/portal/Portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,23 @@ import { nanoid } from 'nanoid/non-secure';
import { usePortal } from '../../hooks';
import type { PortalProps } from './types';

const PortalComponent = ({ key: _providedKey, children }: PortalProps) => {
const PortalComponent = ({ name: _providedName, children }: PortalProps) => {
//#region hooks
const { mount, unmount } = usePortal();
//#endregion

//#region variables
const key = useMemo(() => _providedKey || nanoid(), [_providedKey]);
const name = useMemo(() => _providedName || nanoid(), [_providedName]);
//#endregion

//#region effects
useEffect(() => {
mount(key, children);
mount(name, children);
return () => {
unmount(key);
unmount(name);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [key, children]);
}, [name, children]);
//#endregion

return null;
Expand Down
10 changes: 9 additions & 1 deletion src/components/portal/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import type { ReactNode } from 'react';

export interface PortalProps {
key?: string;
/**
* Portal key or name, to be used internally.
* @type string
* @default nanoid generated unique key.
*/
name?: string;
/**
* Portal content.
*/
children?: ReactNode | ReactNode[];
}

0 comments on commit bf6cf1e

Please sign in to comment.