Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const cloneSSRElement = (
element: JSX.Element,
transformChildElements: (
children: JSX.Element | JSX.Element[],
childrenProps: PlainObject,
) => JSX.Element | JSX.Element[],
) => {
if (!isReactFragment(element)) {
throw new Error('Invalid element passed. The top level element must be a fragment');
}
const { children } = getElementProps(element);
const childrenProps = getElementProps(children);
return cloneElement(element, {}, transformChildElements(children, childrenProps));
};
export const cloneSSRElement = (
element: JSX.Element,
transformChildElements: (
children: JSX.Element | JSX.Element[],
childrenProps: PlainObject,
) => JSX.Element | JSX.Element[],
) => {
if (!isReactFragment(element)) {
throw new Error('Invalid element passed. The top level element must be a fragment');
}
const { children } = getElementProps(element);
const childrenProps = getElementProps(children);
return cloneElement(element, {}, transformChildElements(children, childrenProps));
};
const resolvedChildren = Children.toArray(children).reduce((acc: ReactNode[], child: ReactNode) => {
if (isReactFragment(child)) {
return [...acc, ...Children.toArray(child.props.children)];
} else {
return [...acc, child];
}
}, []);