Reputation: 29
What is causing the error?
API_URL and title doesn't work PS shows "Unexpected template string expression"
const API_URL ='http://www.omdbapi.com?apikey=ed015dd';
const App = () => {
const searchMovies = async (title) => {
const response = await fetch('${ API_URL} & s=${title}')
const data = await response.json();
console.log(data.search)
}
useEffect(() => {
searchMovies('spiderman')
}, []);
Upvotes: 1
Views: 103
Reputation: 306
I think you want to use JS template literals. You have to use the backticks (`) instead of single quotes (').
const response = await fetch(`${API_URL}&s=${title}`);
Upvotes: 1