返回诺言的功能,这是一旦承诺解决的选项
在我的代码LoadOptions中,给我以下错误消息“返回承诺的函数,这是一旦承诺解决的选项。”但是我已经在代码中尝试了一些尝试,但没有成功。谁能帮助我了解Loadoptions中出现的此错误?
import { useState } from 'react';
import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet';
import AsyncSelect from 'react-select/async';
import { fetchLocalMapBox } from '../api';
const initialPosition = {
lat: -22.7532328,
lng: -43.4563604
}
type Place = {
label?: string;
value?: string;
position: {
lat: number;
lng: number;
};
}
function OrderLocation() {
const [address, setAddress] = useState<Place>({
position: initialPosition
})
const loadOptions = async (inputValue: string, callback: (places: Place[]) => void) => {
const response = await fetchLocalMapBox(inputValue);
const places = response.data.features.map((item: any) => {
return ({
label: item.place_name,
value: item.place_name,
position: {
lat: item.center[1],
lng: item.center[0]
},
place: item.place_name,
});
});
callback(places);
};
<div className="filter-container">
<AsyncSelect
placeholder="Digite um endereço para entregar o pedido"
className="filter"
loadOptions={loadOptions}
onChange={value => handleChangeSelect (value as Place)}
/>
In my code loadOptions gives me the following error message " Function that returns a promise, which is the set of options to be used once the promise resolves." but I've already made some attempts in the code but without success. Can anyone help me understand this error presented in loadOptions ?
import { useState } from 'react';
import { MapContainer, TileLayer, Marker, Popup } from 'react-leaflet';
import AsyncSelect from 'react-select/async';
import { fetchLocalMapBox } from '../api';
const initialPosition = {
lat: -22.7532328,
lng: -43.4563604
}
type Place = {
label?: string;
value?: string;
position: {
lat: number;
lng: number;
};
}
function OrderLocation() {
const [address, setAddress] = useState<Place>({
position: initialPosition
})
const loadOptions = async (inputValue: string, callback: (places: Place[]) => void) => {
const response = await fetchLocalMapBox(inputValue);
const places = response.data.features.map((item: any) => {
return ({
label: item.place_name,
value: item.place_name,
position: {
lat: item.center[1],
lng: item.center[0]
},
place: item.place_name,
});
});
callback(places);
};
<div className="filter-container">
<AsyncSelect
placeholder="Digite um endereço para entregar o pedido"
className="filter"
loadOptions={loadOptions}
onChange={value => handleChangeSelect (value as Place)}
/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
态
但不是一次。如果您使用的是返回承诺的
async函数
,请通过返回
使该值解决承诺。不要接受回调:The docs say
…but not both at once. If you are using an
async function
which returns a promise, resolve the promise with the options byreturn
ing the value. Do not accept a callback: