Skip to content

Instantly share code, notes, and snippets.

@coryhouse
Created August 23, 2019 12:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coryhouse/3bb2d1eed7a41f5a87131823b9312085 to your computer and use it in GitHub Desktop.
Save coryhouse/3bb2d1eed7a41f5a87131823b9312085 to your computer and use it in GitHub Desktop.
str // strings
<Cmp /> // components
<Cmp {...{ a, b, }} /> // instead of a={a} b={b}. yes, it's less performant
foo && <Cmp /> // shows if truthy
foo === somevalue && <Cmp /> // shows if foo is somevalue
!foo && <Cmp /> // shows if falsy
foo !== somevalue && <Cmp /> // shows if foo is not somevalue
arr.length > 0 && <Cmp /> // shows if array has at least 1 item
arr.length === 0 && <Cmp /> // shows if array is empty
arr.map(({ id }) => <Cmp key={id} />) // renders array
foo ? <CmpA /> : <CmpB /> // show CmpA if foo is truthy, CmpB if not
{
caseA: () => <CmpA />,
caseB: () => <CmpB />,
undefined: () => <CmpC />
}[switchValue]() // an inline switch of components based on switchValue
condA ? (
<CmpA />
) : condB ? (
<CmpB />
) : condC ? (
<CmpC />
) : (
<CmpD />
) // chained ternaries - just think of them as else-ifs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment