Skip to content

Instantly share code, notes, and snippets.

@gabrielmlinassi
Last active December 13, 2022 18:39
Show Gist options
  • Save gabrielmlinassi/3d2fd45f401a57653ce8632091288dc6 to your computer and use it in GitHub Desktop.
Save gabrielmlinassi/3d2fd45f401a57653ce8632091288dc6 to your computer and use it in GitHub Desktop.
Example working with variant
import { EExperimentVersion } from '@/types'
import ProductCardA, { type IProductCardAProps } from './ProductCardA'
import ProductCardC, { type IProductCardCProps } from './ProductCardC'
type PropsVariantA = {
variant?: Extract<keyof typeof EExperimentVersion, 'a'>
} & IProductCardAProps
type PropsVariantC = {
variant?: Extract<keyof typeof EExperimentVersion, 'c'>
} & IProductCardCProps
type PropsVariants = PropsVariantA | PropsVariantC
const ProductCard = ({ variant = 'a', ...props }: PropsVariants) => {
switch (variant) {
case 'c':
return <ProductCardC {...(props as PropsVariantC)} />
default:
return <ProductCardA {...(props as PropsVariantA)} />
}
}
export default ProductCard
// ---------------------------------------
// Usage:
//
export const HomeTemplate = () => (
<>
<Experiment variant='a'>
<FeaturesBanner />
<HomeHeroSection version='c' />
<React.Suspense fallback={null}>
<HomeHowItWorkSection />
<HomeLessTimeCookingSection />
<HomeSaveTimeSection />
<HomeReviewSection />
<HomeSuvieMealSection />
<FinalCallToActionSection />
</React.Suspense>
</Experiment>
<Experiment version='b'>
<FeaturesBanner />
<HomeHeroMealCentricSection />
<React.Suspense fallback={null}>
<HomeMealCentricSealsSection />
<HomeMeetMealKitSystemSection />
<HomeMealKitSelfCookSection />
<HomeTrialMealCentricSection />
<HomeMealCentricSection />
<HomeReviewSection />
<HomeCookingMethodsSection />
<FinalCallToActionSection />
</React.Suspense>
</Experiment>
</>
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment