Redux Toolkit Query轮询引发无数据变更时组件重复渲染问题求助
数据未变更但轮询时组件重复渲染问题
数据本身没有变化,但每次轮询请求执行时,组件仍会出现重渲染情况。我查资料了解到selectFromResult属性可以仅获取数据本身,而非isFetching这类额外状态属性,以下是我的相关代码:
API Slice 中的查询定义
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, }, );
内容的提问来源于stack exchange,提问作者AlmaG3st
相关产品推荐
相关产品推荐

