2

I want to make an API call with some params, and use the selectors to get that values in my components I am getting data in below implementation

const { data, isLoading, isFetching, error } = useGetDomainsQuery({
    search: search || '',
    status: status || '',
    page_number: pageNo,
    page_size: pageRow,
  });

whereas, I am not getting data in selector

dispatch(
    api.endpoints.getDomains.initiate({
      search: search || '',
      status: status || '',
      page_number: pageNo,
      page_size: pageRow,
    }),
  ); 

Selector:-

export const selectDomainsResult = api.endpoints.getDomains.select();

const selectDomainsData = createSelector(
  selectDomainsResult,
  (domainsResult) => domainsResult.data, 
);


export const {
  selectAll: selectAllDomains,
  selectById: selectDomainById,
  selectIds: selectDomainIds,
} = domainsAdapter.getSelectors(
  (state) =>
     selectDomainsData(state) ?? initialState,
);

and using my selector like this

const domains = useSelector(selectAllDomains);

this implementation always gets uninitialised and returns empty array users: []

Ayaz Sayyed
  • 123
  • 1
  • 1
  • 5

1 Answers1

0

The selector you have created with api.endpoints.getDomains.select() will give you the cache entry for calling initiate() or initiate(undefined) but not initiate(something) - for that you would have to use select(something).

phry
  • 35,762
  • 5
  • 67
  • 81