scrimba
Learn React Router
Search Params
Back to all vans
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

AboutCommentsNotes
Back to all vans
Expand for more info
pages
Host
HostVans.jsx
run
preview
console
import React from "react"
import { Link } from "react-router-dom"

export default function HostVans() {
const [vans, setVans] = React.useState([])

React.useEffect(() => {
fetch("/api/host/vans")
.then(res => res.json())
.then(data => setVans(data.vans))
}, [])

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">
{
vans.length > 0 ? (
<section>
{hostVansEls}
</section>

) : (
<h2>Loading...</h2>
)
}
</div>
</section>
)
}
Console
/host/vans/1
-2:12