Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
jsx-dom-runtime
Advanced tools
A tiny in 500 bytes library to JSX syntax templates for DOM.
npm i jsx-dom-runtime
# or
yarn add jsx-dom-runtime
.babelrc
{
"presets": [
"jsx-dom-runtime/babel-preset"
]
}
import { createRef } from 'jsx-dom-runtime';
const App = () => {
const List = createRef();
const addItem = () => {
// append to the end of the list
<List.current>
<li>New Item</li>
</List.current>
};
return (
<>
<button type="button" onclick={addItem}>
Add Item
</button>
<ul ref={List} />
</>
);
};
// append to the end of the head
<document.head>
<link rel="stylesheet" href="/style.css" />
</document.head>;
// append to the end the the body
<document.body id="root">
<App />
</document.body>;
import { createRef } from 'jsx-dom-runtime';
let i = 0;
const ref = createRef();
const clickHandler = () => {
ref.current.textContent = ++i;
};
<document.body>
<p ref={ref}>{i}</p>
<button type="button" onclick={clickHandler}>
+ 1
</button>
</document.body>;
const autofocus = (node) => {
setTimeout(() => node.focus(), 100);
};
<document.body>
<input type="text" ref={autofocus} />
</document.body>;
Add custom attributes behavior
import { Extend } from 'jsx-dom-runtime';
Extend({
/**
* @param {HTMLElement} node
* @param {string[]} value
*/
classList(node, value) {
node.setAttribute('class', value.filter(Boolean).join(' '));
},
/**
* @param {HTMLElement} node
* @param {Record<string, string>} value
*/
dataset(node, value) {
for (let key in value) {
node.dataset[key] = value[key];
}
},
});
<document.body>
<div
classList={['one', 'two']}
dataset={{ testid: 'test', hook: 'text' }}
/>
</document.body>;
Result
<div class="one two" data-testid="test" data-hook="text"></div>
Get template from string
import { Template } from 'jsx-dom-runtime';
<document.body>
<Template>
{`<svg width="24" height="24" aria-hidden="true">
<path d="M12 12V6h-1v6H5v1h6v6h1v-6h6v-1z"/>
</svg>`}
</Template>
</document.body>
FAQs
A tiny in 500 bytes library to JSX syntax templates for DOM. Support HTML, SVG and MathML tags
The npm package jsx-dom-runtime receives a total of 107 weekly downloads. As such, jsx-dom-runtime popularity was classified as not popular.
We found that jsx-dom-runtime demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.