Arna
Arna

Reputation: 29

'API_URL' is assigned a value but never used

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

Answers (1)

Bihan Viranga
Bihan Viranga

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

Related Questions