Created
August 25, 2023 04:45
-
-
Save xianminx/46fe8875623b420ba589e83540612a06 to your computer and use it in GitHub Desktop.
solid-createResource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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