-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;
0

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.