I am using react-native and I have fetch GET request which takes an array. Now I need this fetch() to finish getting that array so I can call a function which will handle this array and do something with it. How do I wait for it to finish?
This is my request:
componentWillMount() {
console.log("will mount");
fetch('SOME_API', {
method: "GET",
headers: {
Accept: 'text/javascript',
'Content-Type': 'text/javascript',
}
}).then(response = >response.json()).then(responseJson = >{
this.setState(function(prevState, props) {
return {
questions: responseJson,
loading: false
}
})
})
}
And when this get request puts responseJson in state I want to call my function that will do something with that array.
If you need any more info please comment.