I'm trying to ask my api for a list of ids and display them in Select component of antd.
<Select style={{ width: "100%" }}>
{myApi.getIds().then((result) => result.map((value) => {
return <Select.Option value={value}>{value}</Select.Option>
}))}
</Select>
value is string.
getIds returns Promise<string[]>
This returns an error Objects are not valid as a React child (found: [object Promise]). But the value is just a string with an id. What am I missing here?
EDIT: Don't know if it will help anyone, but my solution, based on the accepted answer is:
const [ids, setIds] = useState<string[]>(null);
useEffect(() => {
//some code
if (!ids) {
myApi.getIds().then((result) => setIds(result));
}
// some code
return () => { };
}, [ids]);
// some more code
return (
<>
//render other elements
<Select style={{ width: "100%" }}>
{ids?.map((value) => {
return <Select.Option value={value}>{value}</Select.Option>
})}
</Select>
//render other elements
</>
);