'Pass custom properties in Resource in V4

Bit of a newbie here that recently moved to v4. I have some Resources declared using options to pass some custom property. In React Admin 3 syntax:

<Resource name='mydata' options={{label: "Mylabel", site: site}} list={MyList} />

This is using the options prop to pass down my site property. Since the props injection is removed in React admin V4 - what is a good way to pass this prop to my list component in V4?



Solution 1:[1]

You can still pass the options prop to the Resource component.

And you can get it like this:

const PostList = () => {
    const { options } = useResourceDefinitions();
    // ... 
}

This is somewhat explained in the Upgrade Guide from v3 to v4:

https://marmelab.com/react-admin/Upgrade.html#custom-menus-should-get-resource-definition-from-context

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1