Skip to content

Commit

Permalink
fix(fuselage): multiple div being added with Position (#1039)
Browse files Browse the repository at this point in the history
Co-authored-by: Douglas Fabris <[email protected]>
  • Loading branch information
ggazzo and dougfabris authored Apr 28, 2023
1 parent 05c41c8 commit 9dcf01a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/fuselage/src/components/Position/Position.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
ReactPortal,
ReactElement,
} from 'react';
import { useRef, useMemo, useEffect, cloneElement } from 'react';
import { useRef, useMemo, useEffect, cloneElement, useState } from 'react';
import { createPortal } from 'react-dom';

import type Box from '../Box';
Expand Down Expand Up @@ -38,11 +38,18 @@ const Position = ({
() => ({ position: 'fixed', ...positionStyle }),
[positionStyle]
);
const portalContainer = useMemo(() => {
const [portalContainer] = useState(() => {
const prev = document.getElementById('position-container');
if (prev) {
return prev;
}
const element = document.createElement('div');

element.id = 'position-container';

document.body.appendChild(element);
return element;
}, []);
});

useEffect(
() =>
Expand Down

0 comments on commit 9dcf01a

Please sign in to comment.