首页 > 解决方案 > ReactJS 多箭头函数

问题描述

.then((myJson) => this.setState({example: myJson},() => this.toggleModal()));

我正在从我的 API 中获取数据,然后我调整我的模态以显示一些数据,但是我需要this.example()在模态显示之前执行函数,我已经尝试过;

.then((myJson) => this.setState({example: myJson},() => this.example() ,() => this.toggleModal()));

但是这种方式toogleModal()是不执行的!我该如何解决这个问题?

标签: reactjs

解决方案


就像@Developer 说的,试试吧:

.then((myJson) => this.setState({example: myJson},() => {
      this.example();
      this.toggleModal();
 }));

推荐阅读