summaryrefslogtreecommitdiff
path: root/packages/integrations/react/client.js
blob: fc952522be98d7e59103f3fe7ace950cb1f7dd5e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { createElement } from 'react';
import { createRoot, hydrateRoot } from 'react-dom/client';
import StaticHtml from './static-html.js';

export default (element) =>
	(Component, props, children, { client }) => {
		const componentEl = createElement(
			Component,
			props,
			children != null ? createElement(StaticHtml, { value: children }) : children
		);
		if (client === 'only') {
			return createRoot(element).render(componentEl);
		}
		return hydrateRoot(element, componentEl);
	};