useProp
Reactivity in the scope of the webcomponent without the use of context(this)
Syntax
const [value, setValue] = useProp(myProp);Example
import { useProp } from "atomico";
function useCounter(prop) {
const [value, setValue] = useProp(prop);
return {
value,
increment: () => setValue((value) => value + 1),
decrement: () => setValue((value) => value - 1),
};
}
function component() {
const counter = useCounter("value");
return (
<host>
<button onClick={counter.increment}>+</button>
<strong>{counter.value}</strong>
<button onClick={counter.decrement}>-</button>
</host>
);
}
component.props = {
value: { type: Number, value: 0 },
};Last updated
Was this helpful?
