Skip to content

Instantly share code, notes, and snippets.

@developit
Forked from seveves/index.tsx
Created January 17, 2017 20:21
Show Gist options
  • Save developit/9bcb7e1cedec704a12fc8d43fa384699 to your computer and use it in GitHub Desktop.
Save developit/9bcb7e1cedec704a12fc8d43fa384699 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} key={index} index={index} />))}
</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