0

I just startet learning React Native an got a problem.

i fetch a php file from my server and need to add a ID parameter to the url. the ID parameter is saved in a const.

How can I add my const to the end of the fetch url?

const Round = 1;

return fetch('http://myurl/data.php?ID=')
1

3 Answers 3

2

All you need is to concatenate the Round variable.

const Round = 1;
return fetch('http://myurl/data.php?ID='+Round);

You may also use Template literals

return fetch(`http://myurl/data.php?ID=${Round}`);
Sign up to request clarification or add additional context in comments.

Comments

1

Use template literals:

const round = 1;
return fetch(`http://myurl/data.php?ID=${round}`);

Note: regular variables should have lowercase names, by convention.

Comments

0

Just put const variable at the end

For Example :

const Round = 1;

return fetch('http://myurl/data.php?ID='+Round)

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.