📅  最后修改于: 2022-03-11 15:03:29.758000             🧑  作者: Mango
let component = () => {
let [chartData , setChartData ] = useState();
// an async API call that loads data into chartData state after successful response
return(
{chartData &&
)
}
/* initially, chartData state will be undefined, thus the code block inside the
return will evaluate to undefined ie. it will not be rendered.
once the API response is received and charData will be assigned some real data, the component will rerender.
this time, the code block will not evaluate to undefined. ie. the code block will render
*/
// for a more detailed discussion, read the below article
https://daveceddia.com/watch-out-for-undefined-state/