Skip to content

Instantly share code, notes, and snippets.

@stoneboyindc
Created September 12, 2019 17:04
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 stoneboyindc/29fcb96a95189dc0c33c857667fedf64 to your computer and use it in GitHub Desktop.
Save stoneboyindc/29fcb96a95189dc0c33c857667fedf64 to your computer and use it in GitHub Desktop.
Revised Cart component
import React, { Component } from 'react';
import Total from './Total';
const USCurrencyFormat = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD'
});
class Cart extends Component {
constructor(props) {
super(props);
}
render() {
let summary = null;
if (this.props == null || this.props.selected == null) {
summary = "";
} else {
const summary = Object.keys(this.props.selected).map((feature, idx) => {
const featureHash = feature + '-' + idx;
const selectedOption = this.props.selected[feature];
return (
<div className="summary__option" key={featureHash}>
<div className="summary__option__label">{feature} </div>
<div className="summary__option__value">{selectedOption.name}</div>
<div className="summary__option__cost">
{USCurrencyFormat.format(selectedOption.cost)}
</div>
</div>
);
});
}
return (
<section className="main__summary">
<h2>Your cart</h2>
{summary}
<Total selected={this.props.selected}/>
</section>
)
}
}
export default Cart;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment