Skip to content

Instantly share code, notes, and snippets.

@xianminx
Created August 25, 2023 04:45
Show Gist options
  • Save xianminx/46fe8875623b420ba589e83540612a06 to your computer and use it in GitHub Desktop.
Save xianminx/46fe8875623b420ba589e83540612a06 to your computer and use it in GitHub Desktop.
solid-createResource
const fetchProducts = async () => {
const res = await fetch('https://fakestoreapi.com/products');
const data = await res.json();
return data;
}
export default function ProductList() {
const [products] = createResource(() =>
fetchProducts()
);
return (
<div>
<h1>Products</h1>
<ul>
{products().map((product: any) => (
<li key={product.id}>
<Link href={`/products/${product.id}`}>
{product.title}
</Link>
</li>
))}
</ul>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment