我试图PromiseValue
在renderSelect 中获取。(在tmp
)
问题是我得到了一个Promise,这是正常的行为。但我不明白我怎么能在 Promise 中获取值,以便我可以使用它们。
我有一个ApiService
类如下
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));
}
而我.jsx
喜欢这个
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)