Ref
Preserving values
import { Component, html } from 'vistajs/dom';
import { bootstrap } from 'vistajs/boot';
Component('app-child', () => {
const buttonRef = ref(1, 'myRef');
const changeRef = () => {
buttonRef.current = buttonRef.current + 1;
};
return () => html`
<button onclick="${changeRef()}">
${buttonRef.current}
</button>
`;
});
const App = Component('app-parent', () => {
const count = signal(0);
return () => html`
<div>
<app-child />
<div>
<button onclick="${() => count.set(count() + 1)}">
${count()}
</button>
</div>
</div>
`;
});
const root = document.querySelector('#root') as Element;
bootstrap(root, App)Manipulating DOM
Last updated