Beispiele
Praxisnahe Beispiele. Live-Demos.
Öffne ein Beispiel im Vollbild: Live-Vorschau und Quellcode liegen nebeneinander.
Öffne ein Beispiel im Vollbild: Live-Vorschau und Quellcode liegen nebeneinander.
Ändere den Namen. Der statische Text wurde beim Bau des Elements festgelegt, der dynamische läuft bei jedem update() erneut. forceUpdate() baut den Baum neu auf, sodass auch der statische Text nachzieht.
static: Hello, Alice
dynamic: Hello, Alice
import 'nuclo' let name = 'Alice' let host: Element | undefined const Greeting = () => div( input({ value: () => name, onInput: (e) => { name = e.currentTarget.value; update() }, }), p('static: ', `Hello, ${name}`), // built once p('dynamic: ', () => `Hello, ${name}`), // runs on every update() ) export const App = () => div( div({ onMount: (el) => { host = el as unknown as Element } }, Greeting()), // Calls Greeting() again and patches the same nodes: the static text // catches up. The explicit form rebuilds only this tree. button('forceUpdate()', { onClick: () => { if (host) forceUpdate(Greeting(), host) }, }), )