From React to Atomico
Atomico inherits part of the React syntax and applies it to webcomponents, with a closer to standard approach.
If you develop with React, you will know 80% Atomico ... now why use Atomico?:
Atomico will not limit your React learning curve, what you learned in Atomico is applicable in React, for example hooks and virtualDOM.
Atomico is 3kB in size which is 7% of React + React-dom.
Better component abstraction, for example the use of the ShadowDOM will avoid the need to use css-in-js like styles-components or emotion, reducing dependencies.
Agnostic Components, what you create with React only works within React, what you create with Atomico works on the web, so you can use your components within React, Vue, Svelte or Html.
Exclusive component for React, the CLI @ atomico / exports automatically generates a wrapper component of your webcomponent for React, improving backward compatibility with React.
The following examples show some differences between React and Atomico.
Counter example
From the example we will highlight the following differences:
In Atomico you only use one import.
useProp
is likeuseState
, but with the difference that useProp references the state from the webcomponent property defined incounter.props
.counter.props
allows us to create the properties of our webcomponent, these are like React's propTypes, but with a big difference they are associated with the instance and can be read and modified by referencing the node, exampledocument.querySelector("my-counter").count = 10;
ReactDom.render
needs a reference to mount the component, in Atomico you only need to create themy-counter
tag to create a new instance of the component.The
<host/>
tag is similar to<> </>
for React, but<host/>
represents the webcomponent instance and every component created with Atomico must return the host tagThis is only readability, but in Atomico by convention we do not use capital letters when naming our component, these are only used when creating the customElement as in line 16, since
Counter
is instantiable.
CustomHooks example
From the example we will highlight the following differences:
The hook api is the same.
the component in Atomico returns the `
<host/>
tag.
Supported hooks
In Atomico you will have the most useful React hooks such as:
useRef
useState
useReducer
useLayoutEffect
useEffect
useMemo
useCallback
useContext: Not supported, event api is better practice than context when using webcomponents, example useChannel****
CSS-in-JS
It is common to see the use of libraries such as Emotion or styled-components to encapsulate styles in React, but these add an additional cost, be it for performance or bundle, in Atomico there is no such cost.
Last updated