javascript - How to use an axios response in another axios get in React JS? -


currently need use axios response in next axios get.

first get:

the first returns version id example 10534.

axios.get('https://jira.example.co.uk/rest/api/2/project/pad/versions', headers) .then(function(response) {     const versionid = response.data.map(function(version){              const vid = version.id;          return vid;     });      return versionid;     })     .catch(err => {          console.error(err, err.stack);     }); 

second get:

now need include versionid in next request

axios.all([     axios.get('https://jira.example.co.uk/rest/api/2/search?jql=project = 10005 , fixversion = versionid order priority desc, key asc', headers),     axios.get('https://jira.example.co.uk/rest/api/2/search?jql=status in (reported) , project = 10005 , fixversion = versionid order priority desc, key asc', headers),     axios.get('https://jira.example.co.uk/rest/api/2/search?jql=status in (confirmed) , project = 10005 , fixversion = versionid order priority desc, key asc', headers))     ])     .then(axios.spread(function (response1, response2, response3) { ... } 

how achieve this?

axios.get('https://jira.example.co.uk/rest/api/2/project/pad/versions', headers) .then(function(response) {     const versionid = response.data.map(function(version){              const vid = version.id;          return vid;     });      getanotherrequest(versionid);     })     .catch(err => {          console.error(err, err.stack);     });   getanotherrequest(versionid){     axios.all([         axios.get(`https://jira.example.co.uk/rest/api/2/search?jql=project = 10005 , fixversion = ${versionid} order priority desc, key asc`, headers),         axios.get(`https://jira.example.co.uk/rest/api/2/search?jql=status in (reported) , project = 10005 , fixversion = ${versionid} order priority desc, key asc`, headers),         axios.get(`https://jira.example.co.uk/rest/api/2/search?jql=status in (confirmed) , project = 10005 , fixversion = ${versionid} order priority desc, key asc`, headers)     ])     .then(axios.spread(function (response1, response2, response3) { ... } } 

but check versionid it's array , not integer, because it's result of map , result of map array.


Comments

Popular posts from this blog

PHP and MySQL WP -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

go - golang pprof for c library code -