uelements
TypeScript icon, indicating that this package has built-in type declarations

0.3.1 • Public • Published

UElements

uelements provides a functional way of defining custom elements.

<my-counter count="10"></my-counter>
import { define, useState } from "uelements";

function Counter({ count = 0 }) {
	const [value, setValue] = useState(count);

	return (
		<>
			<div>Counter: {value}</div>
			<button onClick={() => setValue(value + 1)}>Increment</button>
			<button onClick={() => setValue(value - 1)}>Decrement</button>
		</>
	);
}

define(
	"my-counter",
	(el) => <Counter count={parseInt(el.getAttribute("count") || "0")} />,
	["count"],
	() => console.log("counter cleanup")
);

Courtesy: Preact and uwhen

Package Sidebar

Install

npm i uelements

Weekly Downloads

14

Version

0.3.1

License

ISC

Unpacked Size

96.7 kB

Total Files

11

Last publish

Collaborators

  • kethan