-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Document dynamic resources #5004
Conversation
ebd2388
to
d8eb7fe
Compare
docs/Admin.md
Outdated
- [`loginPage`](#loginpage) | ||
- [`logoutButton`](#logoutbutton) | ||
- [`initialState`](#initialstate) | ||
- [`history`](#history) | ||
- [Internationalization](#internationalization) | ||
- [Declaring resources at runtime](#declaring-resources-at-runtime) | ||
- [Use a Function As its Child](#use-a-function-as-its-child) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should link to level 3 headers in this list
docs/Admin.md
Outdated
You might want to dynamically define the resources when the app starts. The `<Admin>` component accepts a function as its child and this function can return a Promise. If you also defined an `authProvider`, the child function will receive the result of a call to `authProvider.getPermissions()` (you can read more about this in the [Authorization](./Authorization.md) chapter). | ||
You might want to dynamically define the resources when the app starts. | ||
|
||
### Use a Function As its Child |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
### Use a Function As its Child | |
### Using a Function As `<Admin>` Child |
docs/Admin.md
Outdated
@@ -559,13 +559,16 @@ The `i18nProvider` props let you translate the GUI. The [Translation Documentati | |||
|
|||
## Declaring resources at runtime | |||
|
|||
You might want to dynamically define the resources when the app starts. The `<Admin>` component accepts a function as its child and this function can return a Promise. If you also defined an `authProvider`, the child function will receive the result of a call to `authProvider.getPermissions()` (you can read more about this in the [Authorization](./Authorization.md) chapter). | |||
You might want to dynamically define the resources when the app starts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sentence alone with the section title afterwards feels odd.
docs/Admin.md
Outdated
@@ -595,6 +598,44 @@ const App = () => ( | |||
); | |||
``` | |||
|
|||
### Unplug the <Admin> using the `<AdminContext>` and the `<AdminUI>` | |||
|
|||
Setting Resources dynamically is still very cumbersome: even if `<Admin>` accepts [a function as child](#declaring-resources-at-runtime), this function can't execute hooks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Setting Resources dynamically is still very cumbersome: even if `<Admin>` accepts [a function as child](#declaring-resources-at-runtime), this function can't execute hooks. | |
Setting Resources dynamically using the children-as-function syntax may not be enough in all cases, because this function can't execute hooks. |
docs/Admin.md
Outdated
|
||
Setting Resources dynamically is still very cumbersome: even if `<Admin>` accepts [a function as child](#declaring-resources-at-runtime), this function can't execute hooks. | ||
|
||
So it's impossible, for instance, to have a dynamic list of resources based on a call to the dataProvider (since the dataProvider is only defined after the Admin component renders). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it's impossible, for instance, to have a dynamic list of resources based on a call to the dataProvider (since the dataProvider is only defined after the Admin component renders). | |
So it's impossible, for instance, to have a dynamic list of resources based on a call to the `dataProvider` (since the `dataProvider` is only defined after the `<Admin>` component renders). |
docs/Admin.md
Outdated
|
||
So it's impossible, for instance, to have a dynamic list of resources based on a call to the dataProvider (since the dataProvider is only defined after the Admin component renders). | ||
|
||
To do so, you have to build your own <Admin> component using both the <AdminContext> and the <AdminUI> (as we do internally). It's straightforward. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add backticks around components
docs/Admin.md
Outdated
|
||
So it's impossible, for instance, to have a dynamic list of resources based on a call to the dataProvider (since the dataProvider is only defined after the Admin component renders). | ||
|
||
To do so, you have to build your own <Admin> component using both the <AdminContext> and the <AdminUI> (as we do internally). It's straightforward. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To do so, you have to build your own <Admin> component using both the <AdminContext> and the <AdminUI> (as we do internally). It's straightforward. | |
To overcome this limitation, you can build your own `<Admin>` component using two lower-level components: `<AdminContext>` (responsible for putting the providers in contexts) and `<AdminUI>` (responsible for displaying the UI). Here is an example: |
docs/Admin.md
Outdated
const dataProvider = useDataProvider(); | ||
|
||
useEffect(() => { | ||
dataProvider.introspect().then(r => setResources(r)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
introspect isn't a legal dataProvider verb, so you'll have to be more explicit here
Fixes #4629
Follows #3907
Todo