feat: add new 'useCreateHref' and 'useResolvePath' hooks #9161
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements two new hooks that make it possible to resolve paths and create hrefs without specifying a
to
immediately. The reasoning for this is that it allows these methods to be passed to non-React functions where it would not be possible to use hooks or allow iterating over paths without wrapping them in an additional component.For example:
vs.
Although the latter might in some cases be preferable it's not always possible or wanted to create a wrapper component. For example in our application we have a utility function that is used to build props for another component:
https://github.com/keycloak/keycloak-ui/blob/f76259088ee057be54f00e34dbac0ad88af96060/src/components/routable-tabs/RoutableTabs.tsx#L74-L77
Which is then used by spreading the resulting props over said component:
https://github.com/keycloak/keycloak-ui/blob/a6fd2cabfa4f802590b7f75d509326447606102f/src/realm-settings/user-profile/UserProfileTab.tsx#L40-L43
For our application this is required as only specific components are allowed as children where these props are spread, so wrapping things in another component and calling
useHref()
is not possible as these props would not match.Closes #8292, closes #8172