Skip to content

Conversation

@thomasheartman
Copy link
Contributor

@thomasheartman thomasheartman commented Dec 5, 2025

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.

@vercel
Copy link

vercel bot commented Dec 5, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Preview Updated (UTC)
unleash-docs Ignored Ignored Preview Dec 8, 2025 0:13am

@thomasheartman
Copy link
Contributor Author

This PR is part of a stack of 4 bookmarks:

  1. trunk()
  2. update-useUiFlag ← this PR
  3. add-newInUnleash
  4. add-gtmReleaseManagement-flag
  5. mount-new-in-unleash

Created with jj-stack

@github-actions
Copy link
Contributor

github-actions bot commented Dec 5, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Comment on lines +14 to +16
export const useUiFlag = <K extends Flag>(flag: K) => {
const evaluate = useDelayedUiFlagEvaluation();
return evaluate(flag);
Copy link
Contributor Author

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

Suggested change
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.

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.
@github-project-automation github-project-automation bot moved this from New to Approved PRs in Issues and PRs Dec 8, 2025
@thomasheartman thomasheartman merged commit 21acef8 into main Dec 8, 2025
9 checks passed
@github-project-automation github-project-automation bot moved this from Approved PRs to Done in Issues and PRs Dec 8, 2025
@thomasheartman thomasheartman deleted the update-useUiFlag branch December 8, 2025 14:17
@thomasheartman thomasheartman added the 👤 all-human No LLM tools used label Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

👤 all-human No LLM tools used

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants