I'm trying to get the PromiseValue
in the renderSelect. (in tmp
)
The thing is that I'm getting a promise, which is the normal behavior. But I don't understand how could I get the values inside the Promise so I can work with them.
I have an ApiService
class as follows
handleResponse(response) {
if (response.status >= 200 && response.status < 300) {
return response.json();
}
return response.json()
.then((res) => {
throw new Error(res.message);
},
() => {
throw new Error();
});
}
get(url) {
return fetch(`${this.API_URL}${url}`, {
method: 'GET',
headers: this.headers,
})
.then(response => this.handleResponse(response));
}
And my .jsx
like this
const getOptions = (contractor_employee_id) => {
const apiService = new ApiService()
return apiService
.get(`some_url`)
.then(
response => {
return ["toto", "tata", "titi"]
},
err => (console.log("Failed"))
);
};
const renderSelect = (field) => {
const tmp = getOptions(field.id)
console.log(tmp)