[英]Loading screen using Semantic UI React
I'm trying to display a loading screen while the rest of the App complete loading using Semantic UI React.我正在尝试在应用程序的 rest 使用 Semantic UI React 完成加载时显示加载屏幕。
The problem is that when i load the page it shows only the text "Loading" and it renders the Loader properly only after a few seconds like if it didn't have any css.问题是,当我加载页面时,它只显示文本“正在加载”,并且它仅在几秒钟后正确呈现加载器,就像它没有任何 css 一样。 The purpose of having a loader is that it has to be in front of the page while other content renders but if it has the same problem I don't know how to show content only when it rendered and ready to be displayed.
拥有加载器的目的是它必须在页面前面,而其他内容呈现,但如果它有同样的问题,我不知道如何仅在内容呈现并准备好显示时显示内容。
I'm using this code from the semantic ui react webpage ( https://react.semantic-ui.com/elements/loader/#types-loader )我正在使用语义 ui 反应网页中的此代码( https://react.semantic-ui.com/elements/loader/#types-loader )
function App() {
const [loading, setLoading] = useState(true);
useEffect(() => {
setTimeout(() => {
setLoading(false);
}, 2000)
}, [])
return (
<div>
<div style={{ display: loading ? "block" : "none" }}>
<Dimmer active>
<Loader content='Loading' />
</Dimmer>
</div>
<div style={{ display: loading ? "none" : "block" }}>
// Content that needs time to render
</div>
</div>
)
}
export default App;
What can I do in order to display content only when it's done rendering?我该怎么做才能仅在完成渲染时才显示内容?
Try putting it in a Segment
.尝试将其放在
Segment
中。 Furthermore I wouldn't use the technique you use to display or hide things, what I always do is:此外,我不会使用您用来显示或隐藏事物的技术,我总是做的是:
{condition && <Component />}
So in this case your code would be:因此,在这种情况下,您的代码将是:
{loading === true && <Segment><Dimmer active><Loader content='Loading' /></Dimmer></Segment>}
and和
{loading === false && <>
{/* Content that needs time to render */}
</>}
And then of course set loading
to false whenever your API calls are finished.然后当然在您的 API 调用完成时将
loading
设置为 false。
I hope this helps you and answers the question, if not please point it out:).我希望这可以帮助您并回答问题,如果没有,请指出:)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.