atomicojs / atomico

Atomico a micro-library for creating webcomponents using only functions, hooks and virtual-dom.
https://atomicojs.dev
MIT License
1.15k stars 43 forks source link

Support plain function components #94

Closed efoken closed 1 year ago

efoken commented 1 year ago

Is your feature request related to a problem? Please describe. It would be super helpful to have support for rendering functions as components in JSX. An example:

// Just a plain function, no Custom Element...
const CloseIcon = (props) => (
  <svg viewBox="0 0 16 16" width="16" height="16" {...props}>...</svg>
);

// ... can be re-used in JSX like this:
function button() {
  return (
    <host shadowDom>
      <button>
        <CloseIcon aria-hidden="true" />
      </button>
    </host>
  );
}

We can do this in React and for big component libraries this is super helpful, if not needed.

efoken commented 1 year ago

Qwik calls them Lite Components: https://qwik.builder.io/docs/components/lite-components/

UpperCod commented 1 year ago

@efoken it's a good idea, would you like to add this functionality? I can help you understand the render.js code

https://github.com/atomicojs/atomico/blob/master/src/render.js#L62-L116

Theoretically we only need to evaluate if parameter type is of type function and execute it and return it

efoken commented 1 year ago

Yes I would like to try, I already checked the render.js and thought about that, can’t be that hard I think🤔

efoken commented 1 year ago

@UpperCod children do not work, I will send another PR later