Kevin Powell - CommunityKP-C
Kevin Powell - Community17mo ago
55 replies
vic

how to add params in useEffect axios get request

Backend code :

routes.get('/delivery/hotel/:hotelname',(req,res)=>{
const hotelName = req.params.hotelname;
res.json({'name': hotelName}) 
} ) 


In reactjs , i don't know how to make that url cuz the hotelname could be different

I tried like this
useEffect(()=> { 
async function fetchData(){ 
let res= await axios.get('http://localhost:1010/delivery/hotel/:hotelName')
console.log(res)
}
fetchData()
},[])


So idk how to set params in react axios

```
Was this page helpful?