Skip to content

Instantly share code, notes, and snippets.

@ericmasiello
Created March 6, 2020 21:37
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 ericmasiello/546f7460298bb5aa20358706bf72c3e5 to your computer and use it in GitHub Desktop.
Save ericmasiello/546f7460298bb5aa20358706bf72c3e5 to your computer and use it in GitHub Desktop.
// 1. render the Title as SpecialButton
<Title as={SpecialButton}>Click Me</Title>
// 2. Inside the Title function we destructure the `as` and `children` props
// `children` === 'Click Me'
// `as` / `Component` === SpecialButton
// 3. The Title Component now effectively returns this:
<SpecialButton className="title">Click Me</SpecialButton>
// 4. React now steps inside the SpecialButton function passing it two props:
// - `children` === 'Click Me'
// - `className` === 'title'
// 5. React now returns from SpecialButton a button passing it two props along with
// the already applied onClick handler
<button onClick={() => alert('sup?')} className="title">Click Me</button>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment