This demo shows how to propagate the flag bag through the context.
The useFlags()
hook of HappyKit should only be used once per Next.js route, at the top level of the default exported page. You should then pass the feature flags down to each component that needs access to them using props.
But some developers might prefer being able to use context instead. This demo shows how to use FlagBagProvider
and the useFlagBag()
hook to put the flagBag into context and how to access it from a nested component.
Render #1 (Current render){ flags: { ads: true, checkout: "short", discount: 5, purchaseButtonLabel: "Purchase" }, data: { flags: { ads: true, checkout: "short", discount: 5, purchaseButtonLabel: "Purchase" }, resolvedVariantIds: { ads: "on", checkout: "on", discount: "on", purchaseButtonLabel: "on" }, visitor: { key: "1EzOBy5r2P1T3dJcttZbR" } }, error: null, fetching: false, settled: true, visitorKey: "1EzOBy5r2P1T3dJcttZbR" }