Javascript 在turnery操作符中,我如何在几秒钟后返回jsx?
我使用的是这样一个turnery操作员:Javascript 在turnery操作符中,我如何在几秒钟后返回jsx?,javascript,reactjs,Javascript,Reactjs,我使用的是这样一个turnery操作员: { typeof weather.data !== "undefined" ? ( <React.Fragment> <div className="col-lg-6 col-md-6 col-sm-12 col-12 border"> <Details temp={Math.round(weather.data.main.temp)} city
{
typeof weather.data !== "undefined" ? (
<React.Fragment>
<div className="col-lg-6 col-md-6 col-sm-12 col-12 border">
<Details
temp={Math.round(weather.data.main.temp)}
city={weather.data.name}
country={weather.data.sys.country}
date={dateBuilder}
weather={weather.data.weather[0].main}
/>
</div>
</React.Fragment>
) : (
setTimeout(() => {
return (
<div className="d-flex flex-column align-items-center w-100 font">
<img style={{ width: "100px" }} src={require("./assets/wifi.png")} />
<p className="mt-3">Please check your internet connection</p>
</div>
);
}, 3000)
);
}
问题在于,如果weather.data的类型等于undefined,则不会返回
请检查您的连接
3秒后部分基本上setTimeout功能不起作用
那么,如何使用setTimeout在几秒钟后返回值呢?我将使用超时来更新状态中的标志,以显示JSX元素
const connFail = () => {
setTimeout(() => {
this.setState({ connFail: true });
}, 3000);
};
我将使用超时来更新状态中的标志,以显示JSX元素
const connFail = () => {
setTimeout(() => {
this.setState({ connFail: true });
}, 3000);
};