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=')
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
maximus26
  • 65
  • 1
  • 7
  • Possible duplicate of [Concatenating variables and strings in React](https://stackoverflow.com/questions/39523040/concatenating-variables-and-strings-in-react) – Roy Wang Apr 23 '18 at 09:34

3 Answers3

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}`);
Ahsan Ali
  • 4,951
  • 2
  • 17
  • 27
1

Use template literals:

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

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

Colin Ricardo
  • 16,488
  • 11
  • 47
  • 80
0

Just put const variable at the end

For Example :

const Round = 1;

return fetch('http://myurl/data.php?ID='+Round)
Jitender Badoni
  • 218
  • 1
  • 9