how to add params in useEffect axios get request
Backend code :
In reactjs , i don't know how to make that url cuz the hotelname could be different
I tried like this
So idk how to set params in react axios
```
32 Replies
u just put the name there
in the link
Yea , this is first time I use react with backend
it's not anything with react
it's just normal routing
<Routes>
<Route path='/delivery/hotel/:hotelName' element={component} >
So I use useParams to get hotelName
http://localhost:1010/delivery/hotel/customHotelName
Open this url in your browser
make sure your server is online
it should return u "customHotelName"
ooh u r also using react router
Yep
u have to fetch the route
idk react router
but ik that u have to first get the route from the url
like the hotel nsme
then you'll need to add that to the link
I use like this
const hotelName={useParams} and pass on fetch url with hotel name
is it working!
?
console log hotelName
Yes it works
But is it good practice?
i don't know react router so can't really tell
but if hotelName is holding the hotel name properly then u should he able to just do
This is what I did
here u r directly setting :hotelName in the param
Yes that what I done
that's not gon work
this
and this r diff
do this
I use let res= await axios.get(
https://localhost:1010/deliver/hotel/${hotelName}
)hmm... and it is not working?
It works
weird
But this is not working
here it says deliver
Type mistake
on the server u have delivery
ooh ok
make sure u don't have those in your code
Ok
in what sense?
does it give any error?
It takes as a url and send no response
Not as a params
try console logging in the server
console log hotelName
before res.json
see if it is receiving a response
and make sure u have the url full
like here i have skipped the middle part with .....
and no typo
hotelName from router is working but
U r message of
http://localhost:1010/delivery/hotel/customHotelName
Open this url in your browser
make sure your server is online
it should return u "customHotelName"
This is not working
it is not returning anything at all?
Sorry for late , yes its not return anything
np
can u try this
That works
Works only from the react router useParams