Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将类组件转换为函数组件_Javascript_Reactjs - Fatal编程技术网

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();
 }