Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class TodoItem extends React.Component{
- constructor(props){
- super(props)
- }
- removeItem = () => {
- /* code to remove the item*/
- this.props.update()
- }
- render(){
- return(
- <div>{props.title} - <span onClick={this.removeItem}>delete</span></div>
- )
- }
- }
- class TodoItems extends React.Component{
- constructor(props){
- super(props)
- this.state = {items: []}
- this.update = this.update.bind(this)
- this.update()
- }
- update(){
- axios.get("/api").then(r=> this.setState({items: r.data})})
- }
- render(){
- return(
- <div>{this.state.items.map(item => <TodoItem {...item} key={item.id} update={this.update}/> )} </div>
- )
- }
- }
Add Comment
Please, Sign In to add comment