Skip to content

Commit

Permalink
use groupBy in place of custom code, now we're on node 22 and using `…
Browse files Browse the repository at this point in the history
…es-next`
  • Loading branch information
twrichards committed Dec 5, 2024
1 parent d77fb38 commit 04596d2
Showing 1 changed file with 5 additions and 15 deletions.
20 changes: 5 additions & 15 deletions client/src/fronts/frontsIntegration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,11 @@ export const FrontsIntegration = ({
}: {
frontsPinboardElements: HTMLElement[];
}) => {
const pathToElementsMap: { [path: string]: HTMLElement[] } = useMemo(
const pathToElementsMap: Partial<{ [path: string]: HTMLElement[] }> = useMemo(
() =>
frontsPinboardElements.reduce(
// TODO could be replaced with groupBy if we upgrade to Node21 plus set lib to esnext in tsconfig
(acc, htmlElement) =>
htmlElement.dataset.urlPath
? {
...acc,
[htmlElement.dataset.urlPath]: [
...(acc[htmlElement.dataset.urlPath] || []),
htmlElement,
],
}
: acc,
{} as Record<string, HTMLElement[]>
Object.groupBy(
frontsPinboardElements,
(htmlElement) => htmlElement.dataset.urlPath ?? "undefined"
),
[frontsPinboardElements]
);
Expand Down Expand Up @@ -108,7 +98,7 @@ export const FrontsIntegration = ({
<>
{Object.entries(pathToElementsMap).map(
([path, htmlElementsToMountInto]) =>
htmlElementsToMountInto.map((htmlElementToMountInto) =>
htmlElementsToMountInto!.map((htmlElementToMountInto) =>
ReactDOM.createPortal(
<FrontsPinboardArticleButton
maybePinboardData={pathToPinboardDataMap[path]}
Expand Down

0 comments on commit 04596d2

Please sign in to comment.