在 ListContextProvider 中使用 useListController 不会提供数据



我使用的是react-admin,但我遇到的问题是,即使useListContext提供了ListContextProvider内部的任何数据,useListController也不提供。

const query = useQuery({
type: 'getList',
resource: 'dashboard/summary',
payload: {
pagination: { page, perPage },
sort: { field: 'createdAt', order: 'DESC' },
filter
},
});
// more code ....
return (
<ListContextProvider
value={{
...query,
setPage,
basePath,
data: keyBy(query.data, 'id'),
ids: query.data.map(({ id }) => id),
currentSort: { field: 'id', order: 'ASC' },
selectedIds: [],
resource,
page,
perPage,
setFilters
}}
>
<SummaryList onSearch={onSearch} filter={filter} />
</ListContextProvider>
);

SummaryList内部

const context = useListContext();
const cp = useListController(context);
console.log(context);
console.log(cp);

控制器对象

basePath: "/dashboard/summary"
currentSort: Object { field: "id", order: "ASC" }
data: Object {  }
defaultTitle: "Dashboard/summaries"
displayedFilters: Object {  }
error: null
exporter: function defaultExporter(data, _, __, resource)
filter: undefined
filterValues: Object {  }
hasCreate: undefined
hideFilter: function hideFilter(filterName)​
ids: Array []
loaded: true
loading: false
onSelect: function select(newIds)​
onToggleItem: function toggle(id)​
onUnselectItems: function clearSelection()
page: 1
perPage: 10
resource: "dashboard/summary"
selectedIds: Array []
setFilters: function setFilters(filter, displayedFilters, debounce)​
setPage: function setPage(newPage)​
setPerPage: function setPerPage(newPerPage)​
setSort: function setSort(sort, order)​
showFilter: function showFilter(filterName, defaultValue)
total: undefined

上下文对象

{
"data": {
// the data which I omitted
},
"total": 4,
"loading": false,
"loaded": true,
"basePath": "/dashboard/summary",
"ids": [
"2021-05-01",
"2021-05-02",
"2021-05-03",
"2021-05-04"
],
"currentSort": {
"field": "id",
"order": "ASC"
},
"selectedIds": [],
"resource": "dashboard/summary",
"page": 1,
"perPage": 10
}

我应该如何使用useListController

useListController获取List道具(和位置参数(,使用它从dataProvider获取数据,并将其传递给ListContext。

通过调用useListContext((,您可以访问useListController构建的值和回调。

在您的示例中,您正在手动构建ListContext,因此根本不需要useListController

相关内容

  • 没有找到相关文章

最新更新