mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
18 lines
575 B
JavaScript
18 lines
575 B
JavaScript
|
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);
|
||
|
}
|