首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >componentWillMount和render函数之间的ReactJS竞争

componentWillMount和render函数之间的ReactJS竞争
EN

Stack Overflow用户
提问于 2017-06-12 01:48:10
回答 0查看 57关注 0票数 0
代码语言:javascript
复制
export class Dashboard extends React.Component<DashboardProps, IMonthlyCommission>{

    constructor(props) {
        super(props);
        this.state = {};
    }

    componentWillMount() {
        request.get("AffiliateCommissionStatement/GetCommissionDetails").send().end((err, res) => {
            var data: IMonthlyCommission = res.body.Commissions;
            this.setState(data);
        });
    }

    render() { 
       return <div>{this.state[0]}</div> ;
    }
}

在render内部,this.state[0]为null,因为componentWillMount中的ajax调用是异步的。

如何在render和ajax end函数之间创建依赖关系。这样我就不会得到空的异常/

谢谢

EN

回答

页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44486895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档