-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: useUiFlag shorthand hook (#4566)
## About the changes Instead of this: ```ts const { uiConfig } = useUiConfig(); const myFlag = Boolean(uiConfig?.flags?.myFlag) ``` we can have this: ```ts const myFlag = useUiFlag("myFlag") ``` With the same type safety, less verbose and more purposeful code. ### Important files - `frontend/src/hooks/useUiFlag.ts` ## Discussion points Can we in the future share flags between frontend and backend? Right now adding a new flag has to be done in 4 different places (backend flag keys list, backend flags defaults config, backend experimental server options, frontend type). Most ergonomic option is to pull config directly from Unleash. Issue, based on previous user feedback: #4565 Internal feature request document: [docs.google.com/document/d/1Sx0q...](https://docs.google.com/document/d/1Sx0qKZXUVUCjuY5F4MOh1ieOM1A2_jE58zEA7jaM_1g/edit?usp=sharing)
- Loading branch information
Showing
5 changed files
with
22 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; | ||
|
||
type flags = ReturnType<typeof useUiConfig>['uiConfig']['flags']; | ||
|
||
export const useUiFlag = <K extends keyof flags>(flag: K) => { | ||
const { uiConfig } = useUiConfig(); | ||
|
||
return uiConfig?.flags?.[flag] || false; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters