Esempi
Esempi concreti. Demo live.
Scegli un esempio e aprilo a schermo intero: anteprima live e sorgente, fianco a fianco.
Scegli un esempio e aprilo a schermo intero: anteprima live e sorgente, fianco a fianco.
update() ritocca solo la riga dinamica di lang. forceUpdate() richiama App e aggiorna lo stesso <h1>. La forma esplicita ricostruisce solo questo albero, non l'intera pagina.
lang = 'en'
Static text, fixed on build.
import 'nuclo' const labels = { en: { title: 'Hello', body: 'Static text, fixed on build.' }, pt: { title: 'Olá', body: 'Texto estático, fixado na criação.' }, } let lang: keyof typeof labels = 'en' let host: Element | undefined const App = () => div(h1(labels[lang].title), p(labels[lang].body)) export const LanguageSwitch = () => div( p(() => `lang = '${lang}'`), div({ onMount: (el) => { host = el as unknown as Element } }, App()), button('Switch lang, update()', { onClick: () => { lang = lang === 'en' ? 'pt' : 'en'; update() }, }), button('forceUpdate(App(), host)', { onClick: () => { if (host) forceUpdate(App(), host) }, }), )