How to use Portal without rendering the parent element. (If it's a reasonable ask 馃槄) #3149
Answered
by
diegohaz
crisshaker
asked this question in
Questions
-
Portal wraps its children in a In the code snippet below, I want to portal export function MainHeaderPortal(props: MainHeaderPortalProps) {
const [container, setContainer] = React.useState<HTMLElement | null>(null);
useLayoutEffect(() => {
const containerElement = document.getElementById(mainHeaderSlotId);
setContainer(containerElement);
}, []);
return (
<Portal portalElement={container} render={<React.Fragment />}>
{props.children}
</Portal>
);
} I want to know if this is a reasonable ask. If so, any ideas how I can achieve this? |
Beta Was this translation helpful? Give feedback.
Answered by
diegohaz
Dec 4, 2023
Replies: 1 comment 1 reply
-
In that case, since you're not using any special features from Ariakit Portal, simply use return createPortal(children, containerElement); |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
crisshaker
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In that case, since you're not using any special features from Ariakit Portal, simply use
ReactDOM.createPortal
directly: