refactoring

This commit is contained in:
Sriram Hariharan
2023-03-03 23:29:06 -06:00
parent 39016c93aa
commit f47ad8272f
3 changed files with 53 additions and 59 deletions

View File

@@ -0,0 +1,25 @@
import React, { PropsWithChildren, useEffect, useState } from 'react';
import ReactDOM from 'react-dom';
/**
* This adds a new column to the course catalog table header.
* @returns
*/
export default function TableHead({ children }: PropsWithChildren) {
const [portalContainer, setPortalContainer] = useState<HTMLTableCellElement | null>(null);
useEffect(() => {
const portalContainer = document.createElement('th');
portalContainer.setAttribute('scope', 'col');
portalContainer.setAttribute('id', 'ut-registration-plus-table-head');
const lastTableHeadCell = document.querySelector('table thead th:last-child');
lastTableHeadCell!.after(portalContainer);
setPortalContainer(portalContainer);
}, []);
if (!portalContainer) {
return null;
}
return ReactDOM.createPortal(<span>{children}</span>, portalContainer);
}