Skip to content
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

fix: Throw a better error message if context is null #192

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dbasilio
Copy link

@dbasilio dbasilio commented Feb 24, 2025

About the changes

If a developer forgets to render their hooks inside of a FlagProvider, the error message they get doesn't make it super clear what happened. I'm currently getting: react.useContext(...) is null. The unleash client defaults the client to null, but none of the hooks actually treat that as an option and assume it cannot be null.

I added a small hook that reads the context, and if it is null, throws a better error message. I have not made changes to the index.ts file, so this new hook is not exported to consumers. It's internal only to be able to throw a nicer error message.

Closes #

Important files

src/useFlagContext.ts

Discussion points

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Investigating
Development

Successfully merging this pull request may close these issues.

1 participant