0

I am able to change the globally declared searchText from an empty string to "cat" by writing in my input field, but for some reason that isn't updating the string interpolated value of ${searchText}.

Image

2
  • 1) add the relevant code as text, not an image. 2) interpolated strings don't "change" over time, they are what they are based on the substitutions at the time of evaluation. Commented Jan 5, 2021 at 17:10
  • Please edit your question to include the code as text, do not post a link to a painting of it! Commented Jan 5, 2021 at 17:10

1 Answer 1

2

In order to make that dynamic you should be doing something like this:

const apiUrl = () => `...${searchText}...`

You create a function to be executed and return the current value when you need it.

And then when you need to call it:

// just an example...
const url = apiUrl()
fetch(url)...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.