Reputation: 65
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=')
Upvotes: 0
Views: 3816
Reputation: 5135
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}`);
Upvotes: 2
Reputation: 17269
Use template literals:
const round = 1;
return fetch(`http://myurl/data.php?ID=${round}`);
Note: regular variables should have lowercase names, by convention.
Upvotes: 1
Reputation: 212
Just put const variable at the end
For Example :
const Round = 1;
return fetch('http://myurl/data.php?ID='+Round)
Upvotes: 0