Created
January 17, 2017 19:49
-
-
Save seveves/d517e0092a36cb408aac890afd122a8d to your computer and use it in GitHub Desktop.
List and ListItem Preact
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, h } from 'preact'; | |
import ListItem from '../list-item'; | |
export default class List extends Component<{}, { indices: number[] }> { | |
state = { indices: [0, 1, 2, 3] }; | |
public render() { | |
return ( | |
<div class="sde-list"> | |
{ this.state.indices.map(index => ( | |
<ListItem onAction={this.do} index={index}></ListItem>))} | |
</div> | |
); | |
} | |
private do = (action: string, index: number) => { | |
if (action === 'right') { | |
console.log('Item removed (right): ' + index); | |
} else { | |
console.log('Item removed (left): ' + index); | |
} | |
let indices = this.state.indices; | |
indices.splice(index, 1); | |
this.setState({ indices }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment