Resource
Fetching data
import { signal, resource } from 'vistajs/core';
import { Component, html } from 'vistajs/dom';
import { boostrap } from 'vistajs/boot';
const home = Component('app-home', () => {
const products = resource({
loader: async () => {
const response = await fetch('https://dummyjson.com/products?limit=3');
const data = await response.json();
return data?.products.map((product: any) => product.title);
},
});
return () => html`
<ul>
${products.value()?.map((product: string) => {
return `<li>${product}</li>`;
})}
</ul>
`;
});
const root = document.querySelector('#app') as Element;
boostrap(root, home);Reactive data fetching
States
Loading
Error
Last updated