Skip to content

Commit 6089e3e

Browse files
sayaptawonidugeni
andcommitted
fix: resolve hydration issue
- Fixed hydration mismatch by aligning server-side and client-side rendering. - Adjusted component imports and rendering logic to ensure consistent output between server and client. Co-Authored-By: Jagad Brahma Wiraatmaja <officialelsa21@gmail.com>
1 parent 5a51c7e commit 6089e3e

File tree

7 files changed

+54
-20
lines changed

7 files changed

+54
-20
lines changed

src/components/BubbleMessage.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,22 @@ import { faWhatsapp } from '@fortawesome/free-brands-svg-icons';
77

88
export default function BubbleMessage () {
99
const [isFormVisible, setIsFormVisible] = useState(false);
10+
const [isSent, setIsSent] = useState(false);
11+
const [isPageLoaded, setIsPageLoaded] = useState(false);
1012
const [formData, setFormData] = useState({
1113
name: '',
1214
email: '',
1315
message: '',
1416
});
15-
const [isSent, setIsSent] = useState(false);
1617

1718
useEffect(() => {
1819
setIsSent(false);
1920
}, []);
2021

22+
useEffect(() => {
23+
setIsPageLoaded(true);
24+
}, []);
25+
2126
const handleChange = useCallback((event) => {
2227
const { name, value } = event.target;
2328
setFormData((prev) => ({ ...prev, [name]: value }));
@@ -51,6 +56,10 @@ export default function BubbleMessage () {
5156
}
5257
}, [isSent]);
5358

59+
if (!isPageLoaded) {
60+
return null;
61+
}
62+
5463
return (
5564
<section data-theme='light'>
5665
<button

src/components/Navbar.js

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const Navbar = ({ isOpen, setIsOpen }) => {
2929
const menuRef = useRef(null);
3030
const pathname = usePathname();
3131
const [isDesktop, setIsDesktop] = useState(false);
32+
const [iconsLoaded, setIconsLoaded] = useState(false);
3233

3334
useEffect(() => {
3435
const handleResize = () => {
@@ -62,6 +63,10 @@ const Navbar = ({ isOpen, setIsOpen }) => {
6263
};
6364
}, [setIsOpen, pathname]);
6465

66+
useEffect(() => {
67+
setIconsLoaded(true);
68+
}, []);
69+
6570
const activeLink = (href) =>
6671
pathname === href ? 'bg-primary text-neutral' : '';
6772

@@ -73,24 +78,28 @@ const Navbar = ({ isOpen, setIsOpen }) => {
7378
<div className='container mx-auto flex items-center justify-between px-4 py-3'>
7479
<Link href='/'>
7580
<div className='flex items-center text-xl font-bold btn btn-neutral'>
76-
<FontAwesomeIcon
77-
icon={faReact}
78-
size='lg'
79-
className='text-primary'
80-
/>
81+
{iconsLoaded && (
82+
<FontAwesomeIcon
83+
icon={faReact}
84+
size='lg'
85+
className='text-primary'
86+
/>
87+
)}
8188
<span className='hidden md:inline lg:inline'>
8289
{navbarData.brand}
8390
</span>
8491
</div>
8592
</Link>
8693
{/* Mobile Navbar */}
8794
<div className='lg:hidden relative'>
88-
<button
89-
className='btn btn-square btn-neutral'
90-
onClick={() => setIsOpen(!isOpen)}
91-
>
92-
<FontAwesomeIcon icon={faBars} size='lg' />
93-
</button>
95+
{iconsLoaded && (
96+
<button
97+
className='btn btn-square btn-neutral'
98+
onClick={() => setIsOpen(!isOpen)}
99+
>
100+
<FontAwesomeIcon icon={faBars} size='lg' />
101+
</button>
102+
)}
94103
<div
95104
ref={menuRef}
96105
className={`fixed top-0 left-0 w-full h-screen bg-base-300 bg-opacity-100 transform ${
@@ -100,12 +109,14 @@ const Navbar = ({ isOpen, setIsOpen }) => {
100109
<div className='bg-base-100 p-4'>
101110
<div className='flex justify-between items-center'>
102111
<h2 className='text-2xl font-bold text-white'>Menu</h2>
103-
<button
104-
className='btn btn-circle btn-neutral'
105-
onClick={() => setIsOpen(false)}
106-
>
107-
<FontAwesomeIcon icon={faTimes} size='lg' />
108-
</button>
112+
{iconsLoaded && (
113+
<button
114+
className='btn btn-circle btn-neutral'
115+
onClick={() => setIsOpen(false)}
116+
>
117+
<FontAwesomeIcon icon={faTimes} size='lg' />
118+
</button>
119+
)}
109120
</div>
110121
</div>
111122
<div className='flex flex-col items-center pt-6'>

src/components/Testimonial.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ const Testimonial = () => {
5959
};
6060
}, [resetInterval]);
6161

62-
const { name, photo, testimonial, rating } = testimonials[currentIndex] || {};
62+
const {
63+
name = '',
64+
photo = '',
65+
testimonial = '',
66+
rating = 0,
67+
} = testimonials[currentIndex] || {};
6368

6469
if (!testimonials.length) return null;
6570

src/components/VisitorStatistics.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ const VisitorStatistics = () => {
6565
processVisitorData(data);
6666
};
6767

68-
onValue(visitorsRef, handleValueChange);
68+
try {
69+
onValue(visitorsRef, handleValueChange);
70+
} catch (error) {
71+
console.error('Error subscribing to Firebase data:', error);
72+
}
6973

7074
return () => {
7175
off(visitorsRef, 'value', handleValueChange);

src/pages/about/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ const About = () => {
145145
width={1200}
146146
height={600}
147147
className='w-full h-auto rounded-lg shadow-lg'
148+
priority
148149
/>
149150
</div>
150151

src/pages/layanan/kesehatan/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ const Kesehatan = () => {
6969
width={1200}
7070
height={600}
7171
className='w-full rounded-lg shadow'
72+
priority
7273
/>
7374
</div>
7475

src/pages/layanan/kunjungan-penitipan-barang/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
'use client';
2+
13
import React, { useState } from 'react';
24
import Layout from '@/pages/layout';
35
import Link from 'next/link';
@@ -103,6 +105,7 @@ const KunjunganPenitipanBarang = () => {
103105
height={600}
104106
className='w-full h-auto object-cover rounded-lg shadow-lg'
105107
unoptimized
108+
priority
106109
/>
107110
{/* Badge */}
108111
<div className='absolute top-2 right-2 px-2 py-1 badge-primary text-primary-content rounded-badge text-sm font-bold'>

0 commit comments

Comments
 (0)