Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MarcusHurney/807537e2d9d31c31ea4d5abf3ffdb338 to your computer and use it in GitHub Desktop.
Save MarcusHurney/807537e2d9d31c31ea4d5abf3ffdb338 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import { connect } from 'react-redux';
var Checkout = React.createClass({
render: function() {
return (
<div onClick={this.handleClick}>
<h1>{this.props.cart.length}</h1>
</div>
);
},
handleClick: function() {
console.log(this.props.cart.length); //Logs the length of the cart in the global state
//This number in the console updates properly, but the h1 tag is always 0
}
});
function mapStateToProps(state) {
return { cart: state.cart.currentCart };
}
export default connect(mapStateToProps, null)(Checkout);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment