-
-
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
Introduce useResourceLabel hook #6016
Conversation
djhi
commented
Mar 8, 2021
•
edited
Loading
edited
- Introduce hook
- Use the hook where possible (menu, page titles, etc.)
const resources = useSelector(getResources); | ||
const translate = useTranslate(); | ||
|
||
return (resource: string, pluralize = true): string => { |
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.
Why is it a higher-order function and why isn't the hook simply returning the label? This needs to be explained in the jsDoc I think.
* smart_count: 1, | ||
* _: inflection.humanize(inflection.singularize(resource)), | ||
* }); | ||
* const resourceName = useResourceLabel(resource, false); |
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.
bad syntax: it returns a function
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.
Fixed
|
||
/** | ||
* A hook which will return a translated resource name. It will use the label option of the `Resource` component if provided. | ||
* |
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.
could you add a usage example?
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.
Done
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.
Seing the code is use, I find the API perfectible. The second parameter, true
, isn't very readable if one doesn't know the signature of the hook. Why not pass an options object instead?
-getResourceLabel(resource, true)
+getResourceLabel(resource, { smart_count: 1 })
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.
Needs another rebase...
needs rebase |
f07ae1c
to
67cbcda
Compare