Last active
December 13, 2022 18:39
-
-
Save gabrielmlinassi/3d2fd45f401a57653ce8632091288dc6 to your computer and use it in GitHub Desktop.
Example working with variant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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