How to pass a dynamic value in between get api url?
I have a ref that is connected to the input and want value of that input to be passed into a string. This does not work:
const location = useRef("Warsaw");
"http://api.weatherstack.com/current?&query={location.current.value}"
CodePudding user response:
You have incorrect dynamic string syntax. You should use template literals:
const location = useRef("Warsaw");
let url = `http://api.weatherstack.com/current?&query=${location.current.value}`
CodePudding user response:
You can use template literals
const location = useRef("Warsaw");
const uri = `http://api.weatherstack.com/current?&query=${location.current.value}`