summaryrefslogtreecommitdiff
path: root/packages/renderers/renderer-solid/client.js
blob: 047de819dca12f8a268f5afbb4c77fb2ad02065c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
import { createComponent } from 'solid-js/web';

export default (element) => (Component, props) => {
  // Solid `createComponent` just returns a DOM node with all reactivity
  // already attached. There's no VDOM, so there's no real need to "mount".
  // Likewise, `children` can just reuse the nearest `astro-fragment` node.
  const component = createComponent(Component, {
    ...props,
    children: element.querySelector('astro-fragment'),
  });

  const children = Array.isArray(component)
    ? component
    : [ component ];

  element.replaceChildren(...children);
}