official website createresource

https://docs.solidjs.com/guides/how-to-guides/routing-in-solid/solid-router. Under dynamic routes example, does this example work on your local?
2 Replies
navi.ToTskie
navi.ToTskieOP12mo ago
import { createResource, createSignal, Suspense } from "solid-js";
import { useParams } from "@solidjs/router";
// :point_down: This is an asynchronous function that fetches a user from the jsonplaceholder API
async function fetchUser(id) {
const response = await fetch(`https://jsonplaceholder.typicode.com/users/${id}`);
return response.json();
}
const User = () => {
const params = useParams();
const [data] = createResource(params.id,fetchUser) // :point_left: Pass the dynamic route parameter to the createResource primitive
return (
<Suspense fallback={<p>Loading...</p>}>
<div>
<p>Name: {data().name}</p> {/* :point_left: Access the data returned from the fetchUser function */}
<p>Email: {data().email}</p>
<p>Phone: {data().phone}</p>
</div>
</Suspense>
);
};
export default User;
import { createResource, createSignal, Suspense } from "solid-js";
import { useParams } from "@solidjs/router";
// :point_down: This is an asynchronous function that fetches a user from the jsonplaceholder API
async function fetchUser(id) {
const response = await fetch(`https://jsonplaceholder.typicode.com/users/${id}`);
return response.json();
}
const User = () => {
const params = useParams();
const [data] = createResource(params.id,fetchUser) // :point_left: Pass the dynamic route parameter to the createResource primitive
return (
<Suspense fallback={<p>Loading...</p>}>
<div>
<p>Name: {data().name}</p> {/* :point_left: Access the data returned from the fetchUser function */}
<p>Email: {data().email}</p>
<p>Phone: {data().phone}</p>
</div>
</Suspense>
);
};
export default User;
navi.ToTskie
navi.ToTskieOP12mo ago
why mine is not working
No description
Want results from more Discord servers?
Add your server