scrimba
Learn React Router
Suspense
Putting it all together - defer, Await, Suspense in HostVans
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Putting it all together - defer, Await, Suspense in HostVans
AboutCommentsNotes
Putting it all together - defer, Await, Suspense in HostVans
Expand for more info
pages
Host
HostVans.jsx
run
preview
console
import React from "react"
import { Link, useLoaderData } from "react-router-dom"
import { getHostVans } from "../../api"
import { requireAuth } from "../../utils"

/**
* Challenge: Implement defer, Await, and Suspense in the
* /host/vans route.
*/

export async function loader({ request }) {
await requireAuth(request)
return getHostVans()
}

export default function HostVans() {
const vans = useLoaderData()

const hostVansEls = vans.map(van => (
<Link
to={van.id}
key={van.id}
className="host-van-link-wrapper"
>
<div className="host-van-single" key={van.id}>
<img src={van.imageUrl} alt={`Photo of ${van.name}`} />
<div className="host-van-info">
<h3>{van.name}</h3>
<p>${van.price}/day</p>
</div>
</div>
</Link>
))

return (
<section>
<h1 className="host-vans-title">Your listed vans</h1>
<div className="host-vans-list">
<section>
{hostVansEls}
</section>
</div>
</section>
)
}
Console
/host/vans
-4:37