Heikkisorsa
Heikkisorsa

Reputation: 905

UseQueryWithStore works but useGetList does not

I have a component that fetches a list of items from the data provider like this:

  const { data, total, loading, loaded, error, refetch } = useQueryWithStore({
    type: 'getList',
    resource: 'client/account',
    payload: {
      pagination: {
        page: page + 1,
        perPage: rowsPerPage,
      },
      sort: {
        order: sortOrder,
        field: sortBy,
      },
    },
  })

  if (!loaded) {
    return <Loading />
  }
  if (error) {
    return <p>ERROR</p>
  }
 // render data

Everything works and I can render the list of data in a table.

Now, I wanted to use useGetList specialized hook with this code:

 const { data, total, ids, loading, loaded, error, refetch } = useGetList<ClientAccount>(
    'client/account',
    {
      page: page + 1,
      perPage: rowsPerPage,
    },
    {
      order: sortOrder,
      field: sortBy,
    }
  )

  if (loading) {
    return <Loading />
  }
  if (error) {
    return <p>ERROR</p>
  }
// render

It successfully calls the data provider as it would with useQueryWithStore, it gets the data back from the API, but then all the fields just do not get the fetched data:

I'm using react-admin version 3.14.

What do I do wrong? Should this behave similarly?

Edit: When I inspect the redux actions in Redux DevTools I can see that everything worked properly. It dispatched the following actions:

And for the CUSTOM_QUERY_SUCCESS I see the following output: {"type":"GET_LIST","resource":"client/account","payload":{"pagination":{"page":1,"perPage":20},"sort":{"order":"desc","field":"id"},"filter":{}}}(pin):{data:[{id:'e57…1987} But still, I don't get any data in the destructuring of the useGetList hook.

Edit2: When debugging the code I see that it uses the useGetList from node_modules/ra-core/esm/dataProvider/useGetList.js, but I also see an implementation in node_modules/ra-core/ra-core/dataProvider/useGetList.ts. What's the difference?

Upvotes: 0

Views: 309

Answers (1)

Heikkisorsa
Heikkisorsa

Reputation: 905

useGetList needs a registered Resource in order to work properly while useQueryWithStore doesn't. Adding it resolved the issue.

Upvotes: 2

Related Questions