I'm new in React and currently developing a time based game. On the game, there are a few pages. The problem I am facing right now is that how to continuously add the countdown timer in every page that I will be going. Example, lets say the countdown starts right after when I am on first stage(first page), and after I finished all the task in first stage, I will be going now to 2nd stage with the time continuously ticking down. Already tried adding the timer function but it restarts when going to the other page of the game.
-
What do you mean by "going to the other page of the game"Arseniy-II– Arseniy-II2020-08-14 12:04:59 +00:00Commented Aug 14, 2020 at 12:04
-
the game basically consists of a few pages or scenes. so if you got all the clues and finished all the challenges on the current page you are in, you can access to the next page or scene.clydekarnage– clydekarnage2020-08-15 19:04:16 +00:00Commented Aug 15, 2020 at 19:04
-
Ok. I meant do you change url or what?Arseniy-II– Arseniy-II2020-08-17 06:14:36 +00:00Commented Aug 17, 2020 at 6:14
-
yes sir. so after you finished all the necessary task in the first url or page, you can go to the next.clydekarnage– clydekarnage2020-08-17 07:27:37 +00:00Commented Aug 17, 2020 at 7:27
-
Are you using react-router for url management? If no try to use it. It helps to solve such problems and change url without re rendering componentsArseniy-II– Arseniy-II2020-08-17 13:56:33 +00:00Commented Aug 17, 2020 at 13:56
|
Show 1 more comment
1 Answer
You might want to consider passing the state of the timer from the current page to the page you are travelling to.
Consider this resource, it might be helpful: ReactJS How to transfer data between pages?