Getting started with Atomico for React users
Hi, I'm Atomico js and I bring you the React syntax for webcomponents, I think you and I get along very well π.
import { Button } from "@formas/button/react";
function App(){
return <>
<h1>React App!</h1>
<Button onClick={()=>console.log("Click!")}>
Submit
</Button>
</>
}How to declare a component?
import { useState } from "react";
import ReactDOM from 'react-dom'
function Counter({initialCount}) {
const [count, setCount] = useState(initialCount);
return (
<>
Count: {count}
<button onClick={() => setCount(initialCount)}>Reset</button>
<button onClick={() => setCount(prevCount => prevCount - 1)}>-</button>
<button onClick={() => setCount(prevCount => prevCount + 1)}>+</button>
</>
);
}
render(
<Counter initialCount={1}/>,
document.querySelector("#counter")
);import { c, useProp } from "atomico";
const props = { count: { type: Number, value: 0 } };
const Counter = c(
() => {
const [count, setCount] = useProp("count");
return (
<host>
Count: {count}
<button onClick={() => setCount((prevCount) => prevCount - 1)}>-</button>
<button onClick={() => setCount((prevCount) => prevCount + 1)}>+</button>
</host>
);
},
{ props }
);
customElements.define("my-counter", Counter);How do you declare styles using Atomico?
Instances, children and slots
1. With Atomico you can instantiate CustomElements using its constructor
2. With Atomico you can instantiate components as functions as long as these are only stateless functions
From React to AtomicoVirtualDOM api differencesLast updated
Was this helpful?
