Skip to content

Instantly share code, notes, and snippets.

@faceyspacey
Last active February 21, 2018 10:24
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 faceyspacey/16d49117328a1b5237f99fe6023e9004 to your computer and use it in GitHub Desktop.
Save faceyspacey/16d49117328a1b5237f99fe6023e9004 to your computer and use it in GitHub Desktop.
const MyFirstFunctionalComponent = (props) => {
return (
<div>
{props.num + props.multiplier}
</div>
)
}
class MyFirstClassComponent extends React.Component {
constructor() {
// fill this in
}
multiply = () => { // figure out why this method looks different than render and constructor
// fill this in (clue: it uses `this.setState`)
}
render() {
return (
<div>
<MyFirstFunctionalComponent num={100} multiplier={this.state.multiplier} />
<button onClick={this.multiply}>MULTIPLY!</button>
</div>
)
}
}
// ASSIGNMENT:
// 1) fill in the empty methods
// 2) make this work within CRA
// 3) explain why `multiply` has different syntax than the `render` + `constructor` methods
// 4) rewrite the functional component without braces, parentheses around the JSX, and no `return` keyword
//
// 5) BONUS: create another parent child component pair of components where the parent renders/maps an array
// of numbers or strings, and for each item creates a `<Child />` component, passing that child
// component the number or string as a prop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment