Skip to content

Latest commit

 

History

History
43 lines (39 loc) · 685 Bytes

03.computed-props-state.md

File metadata and controls

43 lines (39 loc) · 685 Bytes

Computed Props and State

Using getters for computed props/state

Computed props

BAD
makeAndName () {
  return `${this.props.make} ${this.props.name}`;
}
GOOD
get brand () {
  return `${this.props.make} ${this.props.name}`;
}

Computed State

BAD
isAccelerating () {
  return this.state.isRunning && this.state.pushingPedal;
}
GOOD
get isAccelerating () {
  return this.state.isRunning && this.state.pushingPedal;
}

render () {
  return (
    <div>
      {this.props.brand}
      {(this.state.running)
        ? <span>is running</span>
        : null
      }
    </div>
  );
}