Javascript 将类组件转换为函数组件
我是一个新的功能组件,这是一个挑战,我有一个类组件,我想从类组件转换到功能组件Javascript 将类组件转换为函数组件,javascript,reactjs,Javascript,Reactjs,我是一个新的功能组件,这是一个挑战,我有一个类组件,我想从类组件转换到功能组件 const initialState = { todo: { done: false } } class UserSummary extends Component { constructor(props) { super(props); this.state = initialState } async componentDidMount() { this.refreshCo
const initialState = {
todo: {
done: false
}
}
class UserSummary extends Component {
constructor(props) {
super(props);
this.state = initialState
}
async componentDidMount() {
this.refreshContent();
}
refreshContent = async () => {
const todos = await todoService.index(this.props.user);
this.props.handleUpdateTodos(todos);
}
handleDeleteToDo = async (todo) => {
await todoService.deleteToDo(todo);
this.refreshContent();
}
handleEditToDo = async (todo, updatedToDo) => {
await todoService.editToDo(todo, updatedToDo);
this.refreshContent();
}