0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00
astro/packages/integrations/react/client-v17.js
Emanuele Stoppa 2dd00a0024
chore: import sort source code, exception for the astro package (#10242)
* chore: import sort source code, exception for the `astro` package

* fix import sorting bug

* Update packages/integrations/lit/server.js

Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>

---------

Co-authored-by: Erika <3019731+Princesseuh@users.noreply.github.com>
2024-02-27 11:15:27 +00:00

22 lines
758 B
JavaScript

import { createElement } from 'react';
import { hydrate, render, unmountComponentAtNode } from 'react-dom';
import StaticHtml from './static-html.js';
export default (element) =>
(Component, props, { default: children, ...slotted }, { client }) => {
for (const [key, value] of Object.entries(slotted)) {
props[key] = createElement(StaticHtml, { value, name: key });
}
const componentEl = createElement(
Component,
props,
children != null ? createElement(StaticHtml, { value: children }) : children
);
const isHydrate = client !== 'only';
const bootstrap = isHydrate ? hydrate : render;
bootstrap(componentEl, element);
element.addEventListener('astro:unmount', () => unmountComponentAtNode(element), {
once: true,
});
};