tiy-tpa-fee / mini-redux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Understanding Props vs State

<Multiply a="4" b="2" />  // => 8
const multiply = (a, b) => {  // <-- Props
  const product = a * b       // <-- State
  return product
}
<Square n="4" />     // ==> 16
class Square extends Component {

   render () {
      return <Multiply a={this.props.n} b={this.props.n} />
   }
}
const square = (n) => {          // <-=  props
  const product = multiply(n, n) // <-- state
  return product
}
// multiply(4, 2)  // => 8

Props are just like parameters/arguments to a function State is like internal variables scoped to a function

About


Languages

Language:JavaScript 79.8%Language:HTML 14.4%Language:CSS 5.7%