Friday, May 17, 2024
 Popular · Latest · Hot · Upcoming
112
rated 0 times [  116] [ 4]  / answers: 1 / hits: 6548  / 3 Years ago, mon, august 30, 2021, 12:00:00

I want to render one component inside my App.Js after some time pass with setTimeout, there is any way to do that?


when I try, nothing happens...


my code:


function App() {
return (
<Router>
<GlobalStyle />

<SearchProvider>
<Header />

<Switch>
<Route exact path="/">
{setTimeout(() => {
return;
<>
<InitialLoad />
<Home />
</>;
}, 1200)}
</Route>

<Route exact path="/series">
<Series />
</Route>
<Route exact path="/movies">
<MoviesPage />
</Route>
<Route exact path="/popular">
<PopularPage />
</Route>
<Route exact path="/resultado-de-busca">
<SearchPage />
</Route>
</Switch>
</SearchProvider>
</Router>
);
}

want my InitialLoad and Home Components show after 1200 time, but nothing happens, how I fix it, please?


More From » reactjs

 Answers
3

If you want to do that in the Route:


import { useState } from "react";

function App() {

const [isDisplayed, setIsDisplayed] = useState(false);

useEffect(() => {
setInterval(() => {
setIsDisplayed(true);
}, 1200);
}, []);

return (
<Router>
<GlobalStyle />

<SearchProvider>
<Header />

<Switch>
<Route exact path="/">
{isDisplayed &&
<>
<InitialLoad />
<Home />
</>;
}
</Route>
//the rest of your component

[#944] Monday, August 23, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
tajo

Total Points: 415
Total Questions: 124
Total Answers: 103

Location: North Korea
Member since Tue, Jun 16, 2020
4 Years ago
tajo questions
Wed, Apr 6, 22, 00:00, 2 Years ago
Wed, Jan 26, 22, 00:00, 2 Years ago
Tue, Dec 1, 20, 00:00, 4 Years ago
Fri, Jul 17, 20, 00:00, 4 Years ago
;