-
-
Notifications
You must be signed in to change notification settings - Fork 813
chore: add a delayed evaluation of UI flags #11091
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
|
This PR is part of a stack of 4 bookmarks:
Created with jj-stack |
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
9453a57 to
ee137c9
Compare
| export const useUiFlag = <K extends Flag>(flag: K) => { | ||
| const evaluate = useDelayedUiFlagEvaluation(); | ||
| return evaluate(flag); |
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.
While this would have been nice to write just as
| export const useUiFlag = <K extends Flag>(flag: K) => { | |
| const evaluate = useDelayedUiFlagEvaluation(); | |
| return evaluate(flag); | |
| export const useUiFlag = useDelayedFlagEvaluation() |
React doesn't like that because the hook is somehow called outside of a different hook, etc. It gives rendering errors, anyway, but this makes it work.
Additionally, the generic type here is necessary to make TS recognize the return type correctly on the other end.
ee137c9 to
5c121eb
Compare
Adds a new hook for UI flag evaluation that returns an evaluation function. This solves a frequent pain point where we can't check if a flag is enabled conditionally (e.g. if we don't know if we have a flag yet) because it's implemented as a hook. The new implementation uses the same evaluation as the old one, but returns the eval function after calling the hook, thereby circumventing the issue and allowing you to eval a flag anywhere in the function body.
5c121eb to
561949a
Compare
Adds a new hook for UI flag evaluation that returns an evaluation function.
This solves a frequent pain point where we can't check if a flag is enabled conditionally (e.g. if we don't know if we have a flag yet) because it's implemented as a hook.
The new implementation uses the same evaluation as the old one, but returns the eval function after calling the hook, thereby circumventing the issue and allowing you to eval a flag anywhere in the function body.