import React from 'react'; import { Stack, Checkbox, IconButton, TextField, DefaultButton } from 'office-ui-fabric-react'; import { Store } from '../store'; interface TodoListItemProps { id: string; todos: Store['todos']; remove: (id: string) => void; complete: (id: string) => void; edit: (id: string, label: string) => void; } interface TodoListItemState { editing: boolean; editLabel: string; } export class TodoListItem extends React.Component { constructor(props: TodoListItemProps) { super(props); this.state = { editing: false, editLabel: undefined }; } render() { const { todos, id, complete, remove } = this.props; const item = todos[id]; return ( {!this.state.editing && ( <> complete(id)} />
remove(id)} />
)} {this.state.editing && ( Save )}
); } private onEdit = () => { const { todos, id } = this.props; const { label } = todos[id]; this.setState({ editing: true, editLabel: this.state.editLabel || label }); }; private onDoneEdit = () => { this.props.edit(this.props.id, this.state.editLabel); this.setState({ editing: false, editLabel: undefined }); }; private onChange = (evt: React.FormEvent, newValue: string) => { this.setState({ editLabel: newValue }); }; }