I have my react element with a couple of functions inside. I want to use the callback of one function inside another function as a variable. Both functions are using Fetch API.
fetchA = () => {
var data = new FormData();
data.append('file', this.state.selectedFile, this.state.selcetedFile.name);
fetch('/files', {method: 'POST', body: data})
.then(response => {
return response.json()})
.then(function(json) {
console.log(json));})
.catch(function(error) {
console.log(error)
});
}
and
fetchB = () => {
fetch('/trust', {method: 'put', body: **HERE**})
.then(response => {
console.log('SUCCESS')})
.catch(function(error) {
console.log(error)
});
}
You can see in the body of the second fetch call is where i would like to reference the json that was generated in the response of my first function. Can anybody recommend a simple solution for this?
fetchBright away whenfetchAis complete? Have you tried just callingfetchB(json);?