Created
March 30, 2021 08:01
-
-
Save evasconcelos/dd7297f3ec70702309ab220b6eb0bbef to your computer and use it in GitHub Desktop.
LSP Example
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
interface CatFact { | |
facts: string[]; | |
color: string; | |
} | |
const CatFactA = ({ facts, color }: CatFact) => { | |
return ( | |
<> | |
{facts.map((fact, index) => ( | |
<p style={{ color }}> | |
Fact {index}: {fact} | |
</p> | |
))} | |
</> | |
); | |
}; | |
const CatFactB = ({ facts, color }: CatFact) => { | |
return ( | |
<ul style={{ color }}> | |
{facts.map((fact) => ( | |
<li>{fact}</li> | |
))} | |
</ul> | |
); | |
}; | |
export default () => { | |
const catFactData: CatFact = { | |
facts: [ | |
"Cats make about 100 different sounds. Dogs make only about 10.", | |
"I don't know anything about cats.", | |
"Domestic cats spend about 70 percent of the day sleeping and 15 percent of the day grooming." | |
], | |
color: "red" | |
}; | |
const abTest = Math.floor(Math.random() * 2) + 1; | |
return ( | |
<div> | |
{abTest === 1 ? ( | |
<CatFactA {...catFactData} /> | |
) : ( | |
<CatFactB {...catFactData} /> | |
)} | |
</div> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment