I needed a prefix for images. Unfortunatelly the provided solution didn't work for me... At first I tried
<ImageField source="prefix + contentUrl"/>
and the solution above...
Eventually I found following solution:
const MyImageField = ({source, record = {}, ...rest}) => {
let clonedRecord = JSON.parse(JSON.stringify(record));
clonedRecord[source] = process.env.REACT_APP_BASE_PATH + clonedRecord[source];
return <ImageField source={source} record={clonedRecord} {...rest}/>;
};
export const ImageList = props => (
<List {...props}>
<Datagrid rowClick="edit">
<MyImageField source="contentUrl"></MyImageField>
</Datagrid>
</List>
);
const dataProvider = baseHydraDataProvider(entrypoint, fetchHydra, apiDocumentationParser);
export default () => (
<HydraAdmin dataProvider={dataProvider} authProvider={authProvider} entrypoint={entrypoint}>
<ResourceGuesser name={"media_objects"} list={ImageList}/>
</HydraAdmin>
);
Somehow i needed a clone, because the function was called multiple times (-> prefix was added x times).
I use this in combination with the API Platform.
Also see:
https://marmelab.com/react-admin/Fields.html#writing-your-own-field-component