Professional Documents
Culture Documents
Use Params
Use Params
jsx:
api fetching
useEffect(() => {
axios.get('http://localhost:1234/api/get-product-by-id?kuchbhi=${kuchbhi}')
?kuchbhi=${kuchbhi}
.then(json => setproductdetail(json.data.ProductById))
.catch(err => console.log(err))
},[])
ON ANY LINK:
<Link to="/products/category/${value}">{card ka code}</link>
HOW IT WORKS:
ab hoga yeh k us path pe / k bad jo bhi likha ayega wo given page open krdega
ab jab api ban gayi toh api run and fetch hogi for that particular thing and then
data ayega
EXAMPLE:
<Route path="/get-product-by-id/:_id" element={<SingleAdDynamic />} />
main.jsx
on page:
import { useParams } from 'react-router-dom'
const { _id } = useParams();
useEffect(() => {
axios.get('http://localhost:1234/api/get-product-by-id?_id=${_id}')
.then(json => setproductdetail(json.data.ProductById))
.catch(err => console.log(err))
},[])