diff options
Diffstat (limited to 'packages/integrations/react/src/client-v17.ts')
-rw-r--r-- | packages/integrations/react/src/client-v17.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/packages/integrations/react/src/client-v17.ts b/packages/integrations/react/src/client-v17.ts new file mode 100644 index 000000000..4ba4bcf60 --- /dev/null +++ b/packages/integrations/react/src/client-v17.ts @@ -0,0 +1,27 @@ +import { createElement } from 'react'; +import { hydrate, render, unmountComponentAtNode } from 'react-dom'; +import StaticHtml from './static-html.js'; + +export default (element: HTMLElement) => + ( + Component: any, + props: Record<string, any>, + { default: children, ...slotted }: Record<string, any>, + { client }: Record<string, string>, + ) => { + 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, + }); + }; |