-
-
Save developit/9bcb7e1cedec704a12fc8d43fa384699 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} 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