-
Notifications
You must be signed in to change notification settings - Fork 210
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
(feat) Allow useConfig() to load configuration from other modules #751
Conversation
Size Change: +372 B (0%) Total Size: 2.13 MB
ℹ️ View Unchanged
|
T = Omit<ConfigObject, "Display conditions" | "Translation overrides"> | ||
>() { | ||
export function useConfig<T = Record<string, any>>( | ||
moduleName: string | null | undefined = undefined |
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 not
moduleName: string | null | undefined = undefined | |
moduleName?: string |
?
@@ -160,26 +160,28 @@ function useNormalConfig(moduleName: string) { | |||
/** | |||
* Use this React Hook to obtain your module's configuration. |
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 suggest renaming moduleName
to something like foreignModuleName
and adding a docstring comment explaining that it is not needed for normal use and indeed should not be used if it can be avoided. Making useConfig
take an options
object as its argument so that users have to type out foreignModuleName
or whatever in order to pass one might be even better.
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.
Thanks Ian! Nice test, too.
Requirements
For changes to apps
If applicable
Summary
Occasionally, we want a module to be able to load the configuration from a different module; this is possible in the underlying configuration API, but not via the
useConfig()
hook. This PR just extends theuseConfig()
hook to allow you to pass an optional module name, in which caseuseConfig()
will return the configuration of that module. Note that the usage of this feature is discouraged as it may add unnecessary coupling between modules.Screenshots
Related Issue
Other