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

Error when using useFeature hook and feature is not defined #734

Open
Tiberriver256 opened this issue Apr 25, 2024 · 0 comments
Open

Error when using useFeature hook and feature is not defined #734

Tiberriver256 opened this issue Apr 25, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@Tiberriver256
Copy link

Current Behavior

When I have code that looks like this:

import { useFeature } from "flagged";

export function Header() {
	const hasV2 = useFeature("v2");

	return <header>{hasV2 ? <h1>My App v2</h1> : <h1>My App v1</h1>}</header>;
}

createRoot(document.getElementById("root")!).render(
	<FlagsProvider features={{ v3: true, moderate: false }}>
		<Header />
	</FlagsProvider>,
);

We get an exception thrown from this split method

Expected Behavior

Would love for it to essentially default to the flag being off if it can't find the flag in the provider and then do something like a console.warn to let me know that the flag is missing rather than throwing a 'cannot split on undefined' error message.

Suggested Solution(s)

Check if the flag doesn't exit
If the flag requested by the hook doesn't exist, treat it as if the flag were disabled and then throw a warning into the console

Your Environment

Software Version
Flagged ^2.0.8
React 17
Browser Chrome
npm/yarn npm
@Tiberriver256 Tiberriver256 added the bug Something isn't working label Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants