-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: add IfEnabled helper #704
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
sdk/nextjs/src/client/IfEnabled.tsx
Outdated
import useVariableValue from './useVariableValue' | ||
|
||
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types | ||
export const ifEnabled = <T extends { default: ComponentType<any> }>( |
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.
is there a better name than ifEnabled
, maybe renderIfEnabled
?
@@ -6,6 +6,7 @@ import { getUserAgent } from './userAgent' | |||
import { getAllVariables } from './getAllVariables' | |||
import { getAllFeatures } from './allFeatures' | |||
import { DevCycleNextOptions } from '../common/types' | |||
import { ComponentProps, ComponentType, lazy } from 'react' |
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.
are these used? can they be cleaned up?
Add a helper for dynamically importing components into the client bundle depending on feature flag values.
It's used like this:
The result is that if the flag evaluates to false, the component code is never sent to the client.
If it evaluates to true, the initial rendered content is send by the server and the component is "progressively enhanced" with the interactive JS after the page loads (lazy loaded)