Skip to content
This repository has been archived by the owner on Dec 28, 2022. It is now read-only.

Latest commit

 

History

History
5 lines (5 loc) · 547 Bytes

22-June-2018.md

File metadata and controls

5 lines (5 loc) · 547 Bytes

Async calls within componentWillMount

Let's say you do a GET request to server in componentWillMount and set the result to the state. React will execute componentWillMount, and put the stuff in the 'then' on the callback queue and go on executing render() whereupon you will get an error since the callback has not yet been executed and your state is still uninitialized. SO, check for truthy value of whatever it is you are rendering in render() while trying to render it ie {this.state.comment && <span>this.state.comment</span>}