Skip to content

Instantly share code, notes, and snippets.

@codervince
Last active July 6, 2017 06:52
Show Gist options
  • Save codervince/59d98fe6a789c0df23c3ec1b84211cb4 to your computer and use it in GitHub Desktop.
Save codervince/59d98fe6a789c0df23c3ec1b84211cb4 to your computer and use it in GitHub Desktop.
React.Component.js
// Add all useful state specific functions here
export class App extends ReactComponent {
constructor(props){
super(props)
this.state = {products: [{....}]}
//
_handleRemoveLast() {
this.setState({
products: this.state.products.splice(0, this.state.products.length-1)
})
_handleRemoveFirst() {
this.setState({
products: this.state.products.splice(1, this.state.products.length-1)
})
render() {
return (
....
<button onClick={this._handlRemveoLast.bind(this)>Remove last</button>
{this.state.products.map( (p,i) => <Product {...p} key={p.title} />
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment