32
loading...
This website collects cookies to deliver better user experience
Never, ever, setState animations!
Avoid forcing a full component (+ its children) through React and its diffing mechanism 60 times per second.
createSignal
, createStore
, or createMutable
and leave everything else behind.// Make a reactive variable (signal):
const [count, setCount] = createSignal(0)
// Increment the count value every second:
setInterval(() => setCount(count() + 1), 1000)
// Use count in a template:
const div = <div>The count is: {count()}</div>
// The JSX expression gave us back the *real* div element,
// now we can pass it to jQuery or any other DOM API:
jQuery(div).whatever()
console.log(div instanceof HTMLDivElement) // true!
// Even compose the DOM:
const info = <section>Info: {div}</section>
console.log(info instanceof HTMLElement) // true!
import {html} from 'lit-html';
const div = html`<div>Hello World</div>`;
console.log(div instanceof HTMLDivElement) // false!
jQuery(div).foo() // ERROR
html
template tag instead of JSX. Here's an example on CodePen:import html from 'solid-js/html'
import {createSignal} from 'solid-js'
const name = createSignal('Amadar')
// It's just DOM!
const div = html`<div>Hello name is ${name}</div>`
// ... change name later ...
jQuery(div).foo() // It works!
// Even compose the DOM:
const card = html`<section>Profile: ${div}</section>`
console.log(card instanceof HTMLElement) // true!