React.useEffect(() => {
fetch("/api/vans")
.then(res => res.json())
.then(data => setVans(data.vans))
}, [])
/**
* Challenge: filter the list of vans based on the `typeFilter`
* we created earlier. For now, just enter "simple", "luxury",
* or "rugged" into the search param in the URL to check your work.
*/
const vanElements = vans.map(van => (
<div key={van.id} className="van-tile">
<Link to={`/vans/${van.id}`}>
<img src={van.imageUrl} />
<div className="van-info">
<h3>{van.name}</h3>
<p>${van.price}<span>/day</span></p>
</div>
<i className={`van-type ${van.type} selected`}>{van.type}</i>
</Link>
</div>
))
return (
<div className="van-list-container">
<h1>Explore our van options</h1>
<div className="van-list">
{vanElements}
</div>
</div>
)
}
import React from "react"
import { Link, useSearchParams } from "react-router-dom"
export default function Vans() {
const [searchParams, setSearchParams] = useSearchParams()
const [vans, setVans] = React.useState([])
const typeFilter = searchParams.get("type")