I'm really sick of not making any progress
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
"use client";
|
||||
|
||||
import { FC, PropsWithChildren, useEffect, useState } from "react";
|
||||
import { createPortal } from "react-dom";
|
||||
|
||||
@@ -12,9 +14,10 @@ export const Portal: FC<PropsWithChildren<IProps>> = (
|
||||
const [container] = useState(() => {
|
||||
// This will be executed only on the initial render
|
||||
// https://reactjs.org/docs/hooks-reference.html#lazy-initial-state
|
||||
return document.getElementById("root-portal")!;
|
||||
return document.getElementById("root-portal") || document.createElement(el);
|
||||
});
|
||||
|
||||
// todo: this smells. appending the same element?
|
||||
useEffect(() => {
|
||||
container.classList.add(className);
|
||||
document.body.appendChild(container);
|
||||
|
Reference in New Issue
Block a user