【发布时间】:2023-02-21 16:31:27
【问题描述】:
数据没有改变,但组件的重新渲染在每次获取时发生。 我做了一些研究,发现了关于 selectFromResult 属性的信息,只访问数据本身而不是 isFetching prop 或其他
这是我来自 apiSlice 的查询:
getNotification: builder.query<GetNotificationsResponse, GetNotificationsRequest>({
query: ({ page, limit }) => ({
url: `notifications?page=${page}&limit=${limit}`,
method: 'GET',
}),
}),
这是我如何使用轮询和 selectFromResult
const result = useGetNotificationQuery(
{
page: 1,
limit: 10,
},
{
pollingInterval: 1000,
selectFromResult: data => data.data,
},
);
【问题讨论】:
-
const {data, isLoading, isError, error} = useGetNotificationQuery(..
-
是更通用的方法,不确定您是否想要 isFetching,isLoading 仅在没有数据时才会触发,isFetching 会在每次轮询时触发
标签: reactjs redux react-redux redux-toolkit