Tips
La siguiente guía define algunos Tips a considerar al momento de crear webcomponents con Atomico

Component name as function

Write the functional component using the first lowercase character, since the functional declaration is not instantiable as a constructor in JSX.
1
function component() {
2
return <host />;
3
}
Copied!
This prevents confusion when identifying the constructor of the component instance. Atomico if it supports instances as Constructors, see cases.​

useProp

preferably use useProp in the following cases:
  • By modifying the prop from inside the component.
1
function useCounter(prop) {
2
const [value, setValue] = useProp(prop);
3
return {
4
value,
5
increment() {
6
setValue(value + 1);
7
},
8
};
9
}
Copied!
  • By isolating the logic of the prop in a customHook.
1
function useCounter(prop) {
2
const [value, setValue] = useProp(prop);
3
return {
4
value,
5
increment() {
6
setValue(value + 1);
7
},
8
};
9
}
Copied!
In most cases downloading the prop from the first argument of the function is simpler and more declarative, example:
1
function component({ value }) {
2
return <host>{value}</host>;
3
}
4
5
component.props = {
6
value: Number,
7
};
Copied!

Prefers the use of static styles

1
function component() {
2
return <host shadowDom />;
3
}
4
5
component.styles = css`
6
:host {
7
display: block;
8
}
9
`;
Copied!
This does not rule out the use within the style tag, since it is sometimes the solution to the definition of conditional styles or variables to the logic and outside the scope of the custom properties.
Last modified 12d ago