UNPKG

@happykit/flags

Version:

Feature Flags for Next.js

44 lines (41 loc) 1.47 kB
import * as React from 'react'; import { F as Flags, e as FlagBag } from './types-06e22b20.js'; import 'cookie'; /** * This function accesses the `flagBag` from the context. You have to put it there * first by rendering a `<FlagBagProvider value={flagBag} />`. * * _Note that it's generally better to explicitly pass your flags down as props, * so you might not need this at all._ */ declare function createUseFlagBag<F extends Flags = Flags>(): () => FlagBag<F>; /** * If you want to be able to access the flags from context using `useFlagBag()`, * you can render the FlagBagProvider at the top of your Next.js pages, like so: * * ```js * import { useFlags } from "@happykit/flags/client" * import { FlagBagProvider, useFlagBag } from "@happykit/flags/context" * * export default function YourPage () { * const flagBag = useFlags() * * return ( * <FlagBagProvider value={flagBag}> * <YourOwnComponent /> * </FlagBagProvider> * ) * } * ``` * * You can then call `useFlagBag()` to access your `flagBag` from within * `YourOwnComponent` or further down. * * _Note that it's generally better to explicitly pass your flags down as props, * so you might not need this at all._ */ declare function FlagBagProvider<F extends Flags>(props: { value: FlagBag<F>; children: React.ReactNode; }): React.FunctionComponentElement<React.ProviderProps<FlagBag<Flags> | null>>; export { FlagBagProvider, createUseFlagBag };