-1

I am new to JS React, just learn it by following online course, there has the variable inside the URL string, but it unable to return the variable while I running it. May I know how to set the variable inside the URL string correctly?

request.js:

const API_KEY = "xxxxxxxxxxxxxx";

const requests = {
  fetchTrending: '/trending/all/week?api_key=$(API_KEY)&language=en-US',
};

export default requests;
Hugo Yu
  • 105
  • 9

1 Answers1

0

Use Backticks `` and wrap the variable with ${} .

const API_KEY = "xxxxxxxxxxxxxx";
const requests = {
fetchTrending: `/trending/all/week?api_key=${API_KEY}&language=en-US`,
};
export default requests;
Boussadjra Brahim
  • 82,684
  • 19
  • 144
  • 164
Ruhul amin
  • 11
  • 4