Skip to content

Commit

Permalink
refactor: added shouldAddRootHost to provider component
Browse files Browse the repository at this point in the history
  • Loading branch information
gorhom committed Jan 6, 2022
1 parent d84711d commit 9d0a5db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/portalProvider/PortalProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@ import { PortalDispatchContext, PortalStateContext } from '../../contexts';
import { reducer, INITIAL_STATE } from '../../state';
import type { PortalProviderProps } from './types';

const PortalProviderComponent = ({ children }: PortalProviderProps) => {
const PortalProviderComponent = ({
shouldAddRootHost = true,
children,
}: PortalProviderProps) => {
const [state, dispatch] = useReducer(reducer, INITIAL_STATE);
return (
<PortalDispatchContext.Provider value={dispatch}>
<PortalStateContext.Provider value={state}>
{children}
<PortalHost name="root" />
{shouldAddRootHost && <PortalHost name="root" />}
</PortalStateContext.Provider>
</PortalDispatchContext.Provider>
);
Expand Down
7 changes: 7 additions & 0 deletions src/components/portalProvider/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import type { ReactNode } from 'react';

export interface PortalProviderProps {
/**
* Defines whether to add a default root host or not.
*
* @default true
* @type boolean
*/
shouldAddRootHost?: boolean;
children: ReactNode | ReactNode[];
}

0 comments on commit 9d0a5db

Please sign in to comment.