Examples
Practical examples. Live demos.
Pick an example to open it full screen, with the live preview and its source side by side.
Pick an example to open it full screen, with the live preview and its source side by side.
update() refreshes only the dynamic lang line. forceUpdate() calls App again and patches the same <h1>. The explicit form rebuilds only this tree, not the whole page.
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) }, }), )