See in Português (pt-BR) and Espanhol (es-ES).
A tiny React component that conditionally renders its children based on the presence of a cookie (feature flag). Works in both client and server-rendered contexts.
pnpm add react-single-feature-flagimport FeatureFlagGate from "react-single-feature-flag";
export function Example() {
return (
<FeatureFlagGate cookieName="my_feature_flag">
<div>This content shows only when the flag cookie is set</div>
</FeatureFlagGate>
);
}Pass the raw Cookie request header string through the cookieHeader prop.
import FeatureFlagGate from "react-single-feature-flag";
export function ExampleSSR({ cookieHeader }: { cookieHeader: string }) {
return (
<FeatureFlagGate cookieName="my_feature_flag" cookieHeader={cookieHeader}>
<div>SSR-gated content</div>
</FeatureFlagGate>
);
}cookieName: string— Name of the cookie that toggles the feature.cookieHeader?: string— Optional rawCookieheader for SSR. When provided, the component resolves the flag on the server.children: ReactNode— Content to render when the flag is enabled.
- If
cookieHeaderis provided (SSR path), the flag is resolved from that header and the component returnschildrenonly when the cookie is present and truthy; otherwise returnsnull. - If
cookieHeaderis not provided (client path), the component reads fromdocument.cookieon mount and renderschildrenonly when the cookie is present and truthy; otherwise returnsnull. While checking, it returnsnullto avoid flicker.
Componente React simples que renderiza condicionalmente seus filhos com base na presença de um cookie (feature flag). Funciona em contextos de renderização no cliente e no servidor.
pnpm add react-single-feature-flagimport FeatureFlagGate from "react-single-feature-flag";
export function Exemplo() {
return (
<FeatureFlagGate cookieName="meu_feature_flag">
<div>Este conteúdo aparece apenas quando o cookie do flag está definido</div>
</FeatureFlagGate>
);
}Informe a string crua do header Cookie pela prop cookieHeader.
import FeatureFlagGate from "react-single-feature-flag";
export function ExemploSSR({ cookieHeader }: { cookieHeader: string }) {
return (
<FeatureFlagGate cookieName="meu_feature_flag" cookieHeader={cookieHeader}>
<div>Conteúdo controlado por flag no SSR</div>
</FeatureFlagGate>
);
}cookieName: string— Nome do cookie que ativa o recurso.cookieHeader?: string— HeaderCookiecru opcional para SSR. Quando presente, a verificação ocorre no servidor.children: ReactNode— Conteúdo a ser renderizado quando o flag estiver habilitado.
- Se
cookieHeaderfor fornecido (caminho SSR), o flag é resolvido a partir dele e o componente retornachildrenapenas quando o cookie estiver presente e truthy; caso contrário, retornanull. - Se
cookieHeadernão for fornecido (caminho cliente), o componente lê dedocument.cookieno mount e renderizachildrenapenas quando o cookie estiver presente e truthy; caso contrário, retornanull. Durante a verificação, retornanullpara evitar flicker.
Componente de React que renderiza condicionalmente sus hijos según la presencia de una cookie (feature flag). Funciona tanto en cliente como en servidor.
pnpm add react-single-feature-flagimport FeatureFlagGate from "react-single-feature-flag";
export function Ejemplo() {
return (
<FeatureFlagGate cookieName="mi_feature_flag">
<div>Este contenido se muestra solo cuando la cookie del flag está presente</div>
</FeatureFlagGate>
);
}Pase la cadena cruda del encabezado Cookie mediante la prop cookieHeader.
import FeatureFlagGate from "react-single-feature-flag";
export function EjemploSSR({ cookieHeader }: { cookieHeader: string }) {
return (
<FeatureFlagGate cookieName="mi_feature_flag" cookieHeader={cookieHeader}>
<div>Contenido controlado por flag en SSR</div>
</FeatureFlagGate>
);
}cookieName: string— Nombre de la cookie que activa la funcionalidad.cookieHeader?: string— EncabezadoCookiecrudo opcional para SSR. Cuando se proporciona, la verificación ocurre en el servidor.children: ReactNode— Contenido a renderizar cuando el flag esté habilitado.
- Si se proporciona
cookieHeader(ruta SSR), el flag se resuelve desde ese encabezado y el componente devuelvechildrensolo cuando la cookie está presente y es truthy; de lo contrario, devuelvenull. - Si no se proporciona
cookieHeader(ruta cliente), el componente lee desdedocument.cookieal montar y renderizachildrensolo cuando la cookie está presente y es truthy; de lo contrario, devuelvenull. Mientras verifica, devuelvenullpara evitar parpadeo.