File tree Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Expand file tree Collapse file tree 2 files changed +17
-8
lines changed Original file line number Diff line number Diff line change @@ -5,15 +5,24 @@ import FlipClock from "../components/FlipClock";
5
5
import { DatePicker } from "../components/DatePicker" ;
6
6
7
7
export default function Home ( ) {
8
- const [ targetDate , setTargetDate ] = useState (
9
- new Date ( localStorage . getItem ( "targetDate" ) as string ) ??
10
- new Date ( "2025-01-01" )
11
- ) ;
8
+ const [ targetDate , setTargetDate ] = useState ( new Date ( "2025-01-01" ) ) ;
9
+ const [ isInitialized , setIsInitialized ] = useState ( false ) ;
10
+
11
+ // Retrieve target date from localStorage after component mounts
12
+ useEffect ( ( ) => {
13
+ const storedDate = localStorage . getItem ( "targetDate" ) ;
14
+ if ( storedDate ) {
15
+ setTargetDate ( new Date ( storedDate ) ) ;
16
+ }
17
+ setIsInitialized ( true ) ; // Indicate that initialization is complete
18
+ } , [ ] ) ;
12
19
13
- // set target date to local storage
20
+ // Update localStorage whenever targetDate changes (after initialization)
14
21
useEffect ( ( ) => {
15
- localStorage . setItem ( "targetDate" , targetDate . toString ( ) ) ;
16
- } , [ targetDate ] ) ;
22
+ if ( isInitialized ) {
23
+ localStorage . setItem ( "targetDate" , targetDate . toString ( ) ) ;
24
+ }
25
+ } , [ targetDate , isInitialized ] ) ;
17
26
18
27
return (
19
28
< main className = "flex flex-col items-center justify-center h-screen gap-20" >
Original file line number Diff line number Diff line change 1
1
services :
2
2
nextjs :
3
3
image : node:18-alpine
4
- container_name : timer .ayushchugh.com
4
+ container_name : fliptimer .ayushchugh.com
5
5
working_dir : /app
6
6
ports :
7
7
- " 3002:3000"
You can’t perform that action at this time.
0 commit comments