tsx {data.loading? <h1>...loading</h1>:<MyComponent data={current} />}
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 APIasync 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;
const [data,{refetch}] = createResource(params.id,thisProject) refetch()
export default function inProj(){ const params = useParams(); const [data] = createResource(params.id,thisProject) return ( <CredentialUser> <Body> <main class="mt-5 pt-3"> <div class="container-fluid"> <Suspense fallback={<p>..loading</p>}> <div> <p>Name: {data()[0].name}</p> </div> </Suspense> </div> </main> </Body> </CredentialUser> );}
async function thisProject(id) { const response = await fetch( `${import.meta.env.VITE_API_ENDPOINT}/getIdProject`,{ method: 'POST', body: JSON.stringify({ id:parseInt(id) }), headers: { 'Content-type': 'application/json; charset=UTF-8', }, }) return await response.json(); }