Use state instead of ref for main element portal target
Replace mainRef with useState to avoid accessing ref.current during render, which is forbidden by React 19's strict ref rules. Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -190,22 +190,23 @@ export default function AuditsPage(props: Props) {
|
|||||||
setDroppedFile(null);
|
setDroppedFile(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
const mainRef = useRef<HTMLElement | null>(null);
|
const [mainEl, setMainEl] = useState<HTMLElement | null>(null);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
mainRef.current = document.querySelector("main");
|
const el = document.querySelector("main");
|
||||||
if (mainRef.current) {
|
if (el) {
|
||||||
mainRef.current.style.position = "relative";
|
el.style.position = "relative";
|
||||||
|
setMainEl(el);
|
||||||
}
|
}
|
||||||
return () => {
|
return () => {
|
||||||
if (mainRef.current) {
|
if (el) {
|
||||||
mainRef.current.style.position = "";
|
el.style.position = "";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
{isDragging && canCreateAudit && mainRef.current && createPortal(
|
{isDragging && canCreateAudit && mainEl && createPortal(
|
||||||
<div
|
<div
|
||||||
{...getRootProps()}
|
{...getRootProps()}
|
||||||
className="border-primary bg-primary/5 pointer-events-auto absolute inset-0 z-40 flex flex-col items-center justify-center border-2 border-dashed"
|
className="border-primary bg-primary/5 pointer-events-auto absolute inset-0 z-40 flex flex-col items-center justify-center border-2 border-dashed"
|
||||||
@@ -216,7 +217,7 @@ export default function AuditsPage(props: Props) {
|
|||||||
{__("Drop a PDF to create an audit with a report")}
|
{__("Drop a PDF to create an audit with a report")}
|
||||||
</p>
|
</p>
|
||||||
</div>,
|
</div>,
|
||||||
mainRef.current,
|
mainEl,
|
||||||
)}
|
)}
|
||||||
<PageHeader
|
<PageHeader
|
||||||
title={__("Audits")}
|
title={__("Audits")}
|
||||||
|
|||||||
Reference in New Issue
Block a user