Quantcast
Channel: How can I delay rendering until then() of promise completes? - Stack Overflow
Viewing all articles
Browse latest Browse all 3

How can I delay rendering until then() of promise completes?

$
0
0

I'm using reactjs with redux and this is a part of one of my components.

I want to render postList of the promise which is returned by handleFetchPosts, but the render() function starts rendering before the then() of shouldComponentUpdate is completed.

How can I postpone rendering or rerender after the then is completed?

constructor(props) {    super(props);    this.postList = props.postList;    this.props.handleFetchPosts('/main', 'about', '');}shouldComponentUpdate(nextProps) {    if (this.postList !== nextProps.postList) {        nextProps.postList.then(data => {            this.postList = data;        });        return true;    }    else {        return false;    }}render() {    return (<div className="content"><p>                {this.postList +""}                {/*content*/}</p></div>    );}

Viewing all articles
Browse latest Browse all 3

Latest Images

Trending Articles





Latest Images