Skip to content

Commit 7d0cb1a

Browse files
committed
refactor: remove unnecessary Fragment wrapping
Children.only() already validates that the highlight result is a single element, so wrapping it in a Fragment first just to read .props.children back off the wrapper is a no-op. Call Children.only() on the result directly and cast, since the highlight prop is typed as ReactNode.
1 parent 89493fa commit 7d0cb1a

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

src/code-view/internal.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
3-
import { Children, createElement, Fragment, ReactElement, useMemo, useRef } from "react";
3+
import { Children, ReactElement, useMemo, useRef } from "react";
44
import clsx from "clsx";
55

66
import { useCurrentMode } from "@cloudscape-design/component-toolkit/internal";
@@ -56,9 +56,7 @@ export function InternalCodeView({
5656

5757
// Memoize tokenized React nodes to avoid re-running highlight on every render.
5858
const code = useMemo(() => (highlight ? highlight(content) : textHighlight(content)), [content, highlight]);
59-
// Create elements from the nodes.
60-
const codeElementWrapper: ReactElement = createElement(Fragment, null, code);
61-
const codeElement = Children.only(codeElementWrapper.props.children);
59+
const codeElement = Children.only(code) as ReactElement;
6260

6361
return (
6462
<div

0 commit comments

Comments
 (0)