1.0.1 • Published 7 months ago
@zzkit/create-dom v1.0.1
@zzkit/create-dom
Create DOM elements with a declarative React-like syntax.
Usage
Install
npm install @zzkit/create-dom
Import
import { CreateDom } from '@zzkit/create-dom';
Creating elements:
const { createDom } = CreateDom;
const el = createDom('div', {
id: 'container',
style: { color: 'blue' }
},
createDom('h1', {}, 'Hello World'),
createDom('p', {}, 'This is my app')
);
- The first argument is the tag name
- The second argument is props object
- Additional arguments are children
Props
style
- CSS styles object or stringclassName
- CSS classeson[Event]
- Event handlers likeonClick
ref
- Callback ref or object withcurrent
id
,name
,data-*
attributes- And more...
Children
- DOM elements
- Strings (become text nodes)
- Array (becomes fragment - no wrapper element)
Returns
The corresponding DOM element.
// el is <div id="container" style="color: blue">...</div>
You can then append it, return from a function, etc.
License
MIT
1.0.1
7 months ago