import React from 'react';

export default class PriceFlasher extends React.Component {
    constructor(props) {
      super(props);
      this.state = {
        direction: null
      };
    }
    componentWillReceiveProps(nextProps) {
      if (nextProps.price && this.props.price) {
        if (nextProps.price > this.props.price) {
          this.setState({direction: 'upBgFlash'});
        } else if (nextProps.price < this.props.price) {
          this.setState({direction: 'downBgFlash'});
        }
      }
    }
    // shouldComponentUpdate(nextProps, nextState) {
    //   return (nextProps.price !== this.props.price || nextState.direction !== this.state.direction);
    // }
    render() {
      return (
        <td className={'u-' + this.state.direction}>
          {this.props.price}
        </td>
      );
    }
}

PriceFlasher.propTypes = {
  price: React.PropTypes.number
};
