Skip to content

Commit

Permalink
add taco button class component example
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcy Sutton committed Feb 2, 2020
1 parent 92a3dd1 commit 9720a85
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 12 deletions.
27 changes: 27 additions & 0 deletions src/components/taco-component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import React, {Component} from 'react'

class TacoComponent extends Component {
constructor(props) {
super()
this.tacoTopping = props.topping || ''
}
getTacos() {
if (window) {
window.alert(`TACOS! 🌮${this.tacoTopping}`)
}
}
// lifecycle methods here
render () {
return (
<div style={{padding: '1em'}}>
<button
onClick={() => { this.getTacos()}}
style={{fontSize: '1.5em'}}>
Get tacos
</button>
</div>
)
}
}

export default TacoComponent
36 changes: 24 additions & 12 deletions src/slides/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -587,38 +587,50 @@ export default () => {

---

import TacoComponent from '../components/taco-component'

<Slide>

# We still love u, class components
# Class components

<CodeBlock side="left">

```jsx
import React, {Component} from 'react'

class MyComponent extends Component {
constructor() {
class TacoComponent extends Component {
constructor(props) {
super()
this.tacoTopping = props.topping
}
getTacos() {
if (window)
window.alert(`TACOS! 🌮${this.tacoTopping}`)
}
// lifecycle methods here
render {
render () {
return (
<div>
{/* UI stuff here */}
</div>
<button onClick={() => { this.getTacos()}}>
Get tacos
</button>
)
}
}
export default MyComponent
export default TacoComponent
```

</CodeBlock>

</Slide>
<CodeBlock side="right">

---
```jsx
<TacoComponent topping="🌶" />
```

<TacoComponent topping="🌶" />

<img src="../chrome-devtools-component-tree.png" alt="Rendered HTML tree in Chrome devTools" style="max-height: 100vh" />
</CodeBlock>

</Slide>

---

Expand Down

0 comments on commit 9720a85

Please sign in to comment.