2022-03-31 11:51:29 -05:00
|
|
|
import { createElement } from 'react';
|
2024-02-27 06:15:27 -05:00
|
|
|
import { hydrate, render, unmountComponentAtNode } from 'react-dom';
|
2022-03-31 11:51:29 -05:00
|
|
|
import StaticHtml from './static-html.js';
|
|
|
|
|
2022-05-12 11:06:40 -05:00
|
|
|
export default (element) =>
|
2022-06-23 10:10:54 -05:00
|
|
|
(Component, props, { default: children, ...slotted }, { client }) => {
|
|
|
|
for (const [key, value] of Object.entries(slotted)) {
|
|
|
|
props[key] = createElement(StaticHtml, { value, name: key });
|
|
|
|
}
|
2022-05-12 11:05:55 -05:00
|
|
|
const componentEl = createElement(
|
2022-03-31 11:51:29 -05:00
|
|
|
Component,
|
2022-05-12 11:05:55 -05:00
|
|
|
props,
|
2024-08-08 05:12:50 -05:00
|
|
|
children != null ? createElement(StaticHtml, { value: children }) : children,
|
2022-05-12 11:05:55 -05:00
|
|
|
);
|
2023-08-29 09:30:11 -05:00
|
|
|
|
|
|
|
const isHydrate = client !== 'only';
|
|
|
|
const bootstrap = isHydrate ? hydrate : render;
|
|
|
|
bootstrap(componentEl, element);
|
2023-08-29 09:32:02 -05:00
|
|
|
element.addEventListener('astro:unmount', () => unmountComponentAtNode(element), {
|
|
|
|
once: true,
|
|
|
|
});
|
2022-05-12 11:05:55 -05:00
|
|
|
};
|