The documentation of react-admin explains how existing data providers can be extended with own functionalities. As far as I can tell, the code refers to the (old) implementation in Javascript, while most of the code has been migrated to Typescript.
My goal is to override the update method of the ra-data-simple-rest provider to only transfer fields that have actually changed (The issue explains that by default all fields of the object are transferred. To change this behavior, the update method must be modified).
This is the corresponding part of the code in the documentation (no changes made):
import dataProvider from 'ra-data-simple-rest';
const myDataProvider = {
...dataProvider,
update: (resource, params) => {
if (resource !== 'posts' || !params.data.pictures) {
// fallback to the default implementation
return dataProvider.update(resource, params);
}
//... and so on
This leads to the following error:
Property 'update' does not exist on type '(apiUrl: any, httpClient?: ((url: any, options?: Options | undefined) => Promise<{ status: number; headers: Headers; body: string; json: any; }>) | undefined) => DataProvider'. TS2339
6 | if (resource !== 'posts' || !params.data.pictures) {
7 | // fallback to the default implementation
> 8 | return dataProvider.update(resource, params);
| ^
9 | }
10 | /**
11 | * For posts update only, convert uploaded image in base 64 and attach it to
And another question: If the mentioned section works then, where does the dataProvider get the needed parameters "apiUrl" and "httpClient" from?
Update: I also reported this question as an issue on github.
As explained in the updated documentation, you have to change your code as follows:
-import dataProvider from 'ra-data-simple-rest';
+import simpleRestProvider from 'ra-data-simple-rest';
+const dataProvider = simpleRestProvider('http://path.to.my.api/');
Note: please mark the question as resolved if that solved your problem.