【问题标题】:React.js, syntax for handling promises?React.js,处理承诺的语法?
【发布时间】:2016-05-30 04:54:21
【问题描述】:

在 React.js 中处理 Promise 的最佳方式是什么?下面的代码有效 - 有没有更反应的方式?

handleFormSubmit(input){

    this.setState({
        originId: input.originId,
        destinationId: input.destinationId,
        radius: input.radius,
        search: input.search
    });

    var routeSearch = new FindRoutes({
        originPlaceId: input.originId,
        destinationPlaceId: input.destinationId,
        directionsDisplay: directionsDisplay,
        directionsService: directionsService,
        travel_mode: google.maps.TravelMode.DRIVING,
        search: input.search
    });

    routeSearch.execute()
    .then(function(){
        alert("promise fullfilled!");
    });

}

【问题讨论】:

  • 代码没问题。 React 是一个具有 DOM 差异的视图引擎,您不必将它耦合到任何架构。

标签: reactjs promise


【解决方案1】:

这取决于你想要做什么。如果您正在寻找一种很好的方式来组织您的行动并保持一切井井有条。我最近在我的项目中添加了 redux

http://redux.js.org/

而且它很棒,绝对建议您检查一下。他们使用一种称为flux的方法将渲染逻辑与您的操作(即本例中的promise)分开

https://facebook.github.io/flux/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-01
    • 2017-12-20
    • 2022-01-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多