所以我注意到referenceInput
多次调用了API。我遇到的问题与:"Too many request to API endpoint when using ReferenceInput and ReferenceArrayInput"
我不确定这是可以避免的事情还是有解决方法。
如果基础输入支持“选择”,那么最好创建自己的组件。例如我创建了一个自定义自动填充输入,您可以从此处进行提示
const AutocompleteProjectInput = ({ name, label, dataProvider }) => {
const [open, setOpen] = useState(false);
const [options, setOptions] = useState([]);
const loading = !open && options.length === 0;
useEffect(() => {
let active = true;
if (!loading) {
return undefined;
}
(async () => {
const { data: projects } = await dataProvider(GET_LIST, 'projects', {});
if (active) {
setOptions(projects);
}
})();
return () => {
active = false;
};
}, [loading]);
useEffect(() => {
if (!open) {
setOptions([]);
}
}, [open]);
return (
<SelectInput
source="projectId"
choices={options}
optionText="projectName"
optionValue="id"
label={label}
/>
);
};