Skip to content

Instantly share code, notes, and snippets.

@seveves
Created January 17, 2017 19:49
Show Gist options
  • Save seveves/d517e0092a36cb408aac890afd122a8d to your computer and use it in GitHub Desktop.
Save seveves/d517e0092a36cb408aac890afd122a8d to your computer and use it in GitHub Desktop.
List and ListItem Preact
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