Naming
Simple but useful
If you are a React user, it is common for you to make component declarations like these:
export function MyComponent(){
return <>My component in react</>
}Thanks to the previous code in React we can:
Instantiate your component through its function, example
<MyComponent>Friendly export component as module
In Atomico there are some small differences 👇
we recommend in Atomico
Export the return of the c function, since it is instantiable at the JSX level or when using the new operator, example:
export const MyComponent = c(() => <host>My component in Atomico</host>);
customElements.define("my-component", MyComponent);import { MyComponent } from "./my-component";
function app(){
return <host>
<MyComponent/>
</host>
}Instance with operator new: The new operator allows the instance to associate at the TS level the types declared using Atomico
import { MyComponent } from "./my-component";
const component = new MyComponen; Instance with document.createElement
import "./my-component";
const component = document.createElement("my-component");<my-component></my-component>Gracias a lo anterior podemos:
Instantiate your component with TS-level type validation either by using JSX or the new operator with, but remember that to get this type of instances you must first have registered your customElement in the same file or another.
Export the useful component to instantiate.
Prefer this export format because tools like @atomico/exports take advantage of this format to automatically create wrappers for React, Preact, and Vue.
Last updated
Was this helpful?
