【发布时间】:2020-12-12 19:49:59
【问题描述】:
在使用带有自定义查询的 Datagrid 组件时收到以下错误。以下代码适用于 react-admin 版本 3.3.1,而不适用于版本 3.8.1
TypeError:无法读取未定义的属性“包含”
浏览器的控制台信息:列表组件必须在
参考:https://marmelab.com/react-admin/List.html #提示:您可以将 Datagrid 组件与自定义查询一起使用:
import keyBy from 'lodash/keyBy'
import { useQuery, Datagrid, TextField, Pagination, Loading } from 'react-admin'
const CustomList = () => {
const [page, setPage] = useState(1);
const perPage = 50;
const { data, total, loading, error } = useQuery({
type: 'GET_LIST',
resource: 'posts',
payload: {
pagination: { page, perPage },
sort: { field: 'id', order: 'ASC' },
filter: {},
}
});
if (loading) {
return <Loading />
}
if (error) {
return <p>ERROR: {error}</p>
}
return (
<>
<Datagrid
data={keyBy(data, 'id')}
ids={data.map(({ id }) => id)}
currentSort={{ field: 'id', order: 'ASC' }}
basePath="/posts" // required only if you set use "rowClick"
rowClick="edit"
>
<TextField source="id" />
<TextField source="name" />
</Datagrid>
<Pagination
page={page}
perPage={perPage}
setPage={setPage}
total={total}
/>
</>
)
} ```
Please help!
【问题讨论】:
标签: react-admin