1

The question is conceptual, should the dataProvider apply formatting over the data before returning it to react-admin's frontend, or dataProvider must play the role only for data fetcher and must always return the data in the format it comes from the back-end service? What do you think?

What would you do in case you get the data from the back-end deeply nested, in complex structure and you need it simpler for the display? Where would you reduce/format it:

  1. In the dataProvider, right after receiving it from the server and before sending it to React-admin's UI, or
  2. In the UI (a.k.a. Resource view) or maybe
  3. By using a custom reducer: https://marmelab.com/react-admin/Actions.html#using-a-custom-reducer

How is the most elegant and conceptual right way of doing this, in your opinion?

p7adams
  • 622
  • 1
  • 9
  • 24
Ickata
  • 55
  • 1
  • 9

1 Answers1

1

Short answer: you can do both depending on your needs.

This is actually a good question, the answer might be: it depends on the use case.

Firstly, if you are talking of a general data provider related to a specific API format (say ODATA, or GraphQL), it's better to transform the data in the data provider. Even more so if this data provider is open-sourced.

As the documentation says:

[A data provider] is the place to translate data queries to HTTP requests, and HTTP responses to data responses.

That said, if your talking about a specific data provider which is made for your own custom API (or combination or APIs), you can do both: data provider transformations or use custom reducers, or both.

There is nothing wrong to make data transformations in the data provider. You just need to know that React Admin caches the data from the provide in its redux store and does some fancy things like optimistic rendering or undo actions.

Kmaschta
  • 2,369
  • 1
  • 18
  • 36