-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Doc] Update the hooks documentation for consistent TOC #9453
[Doc] Update the hooks documentation for consistent TOC #9453
Conversation
e7c47a5
to
7690839
Compare
The record returned by useRecordContext, useShowController, useShowContext, useEditController and useEditContext is sometimes a cached version of the record or undefined. This is now stated more explicitly in the docs and a link to the caching page is added.
7690839
to
a786c30
Compare
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.
Nice! Although I don't agree with all your proposed changes.
docs/useCreateContext.md
Outdated
```jsx | ||
const { | ||
defaultTitle, // the translated title based on the resource, e.g. 'Create New Post' | ||
redirect, // the default redirection route. Defaults to 'list' | ||
resource, // the resource name, deduced from the location. e.g. 'posts' | ||
save, // the update callback, to be passed to the underlying form as submit handler | ||
saving, // boolean that becomes true when the dataProvider is called to create the record | ||
} = useCreateContext(); | ||
``` |
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 prefer the previous version
docs/useCreateController.md
Outdated
```jsx | ||
const { | ||
defaultTitle, // the translated title based on the resource, e.g. 'Create New Post' | ||
redirect, // the default redirection route. Defaults to 'list' | ||
resource, // the resource name, deduced from the location. e.g. 'posts' | ||
save, // the update callback, to be passed to the underlying form as submit handler | ||
saving, // boolean that becomes true when the dataProvider is called to create the record | ||
} = useCreateController(); | ||
``` |
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 prefer this version
docs/useEditContext.md
Outdated
The `useEditContext` hook returns an object with the same keys as returned by [`useEditController`](./useEditController.md): | ||
|
||
```jsx | ||
const { | ||
defaultTitle, // the translated title based on the resource, e.g. 'Post #123' | ||
error, // error returned by dataProvider when it failed to fetch the record. Useful if you want to adapt the view instead of just showing a notification using the `onError` side effect. | ||
isFetching, // boolean that is true while the record is being fetched, and false once the record is fetched | ||
isLoading, // boolean that is true until the record is available for the first time | ||
mutationMode, // mutation mode argument passed as parameter, or 'undoable' if not defined | ||
record, // record fetched via dataProvider.getOne() based on the id from the location | ||
redirect, // the default redirection route. Defaults to 'list' | ||
refetch, // a function that allows you to refetch the record | ||
resource, // the resource name, deduced from the location. e.g. 'posts' | ||
save, // the update callback, to be passed to the underlying form as submit handler | ||
saving, // boolean that becomes true when the dataProvider is called to update the record | ||
} = useEditContext(); | ||
``` |
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.
Same
docs/useEditController.md
Outdated
|
||
`useEditController` returns an object with the following keys: | ||
|
||
* `defaultTitle`: Translated title based on the resource, e.g. 'Post #123' |
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.
keep the object format
|
||
```jsx |
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.
and the object syntax
@@ -141,39 +141,46 @@ You can disable this feature by setting the `storeKey` prop to `false`. When dis | |||
|
|||
## Return Value | |||
|
|||
The return value of `useListController` has the following shape: |
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.
PLease keep the object format
docs/useSaveContext.md
Outdated
|
||
`useSaveContext` returns an object with the following keys: | ||
|
||
* `save`: Create or update callback which receives form data and calls `dataProvider` |
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.
MAke it a code snippet
docs/useShowContext.md
Outdated
|
||
`useShowContext` returns an object with the same keys as [`useShowController`](./useShowController.md): | ||
|
||
* `defaultTitle`: Translated title based on the resource, e.g. 'Post #123' |
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.
same
docs/useShowController.md
Outdated
|
||
`useShowController` returns an object with the following keys: | ||
|
||
* `defaultTitle`: Translated title based on the resource, e.g. 'Post #123' |
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.
Please use an object in a code snippet
docs/useCreateController.md
Outdated
@@ -43,24 +43,24 @@ export const BookCreate = () => { | |||
|
|||
**Tip**: If you just use the return value of `useCreateController` to put it in an `CreateContext`, use [the `<CreateBase>` component](./CreateBase.md) instead for simpler markup. | |||
|
|||
`useCreateController` accepts an options argument, with the following fields, all optional: | |||
## Arguments |
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.
We use Parameters in most hooks. Why is Arguments better? And if you change it here, you must change it everywhere.
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.
Wasn't sure what's the preference, both work for me. Will change it back soon!
Hey @fzaninotto, thanks for your feedback. My intention to use the listing instead of the object syntax in a codeblock were:
If you still think I should switch back to codeblocks, I will of course do so but imho I think it's neither more readable nor consistent with the rest of the documentation. What do you think? |
I hear your arguments, yet I prefer the code snippet for the return values. |
Any updates? |
Document hooks return values as code blocks with comments. Remove links to Caching page with hints to caching page, as it's not possible to link to other pages from within codeblocks.
Wasn't able to add those changes earlier. |
Thanks! |
Records returned from a context / controller hook are sometimes
undefined
or a cached version of the record. This is now stated more explicitly in the hook documentations for hooks that return the record from a context.Things changed:
Related to #9451