From f09a72f90c049b5e1a8478f737062a24d9c7a3df Mon Sep 17 00:00:00 2001
From: trisusilo48 <tri.susilo@altama.co.id>
Date: Tue, 8 Oct 2024 14:56:00 +0700
Subject: cache localstorage

---
 src/lib/review/components/CustomerReviews.jsx | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

(limited to 'src/lib/review/components/CustomerReviews.jsx')

diff --git a/src/lib/review/components/CustomerReviews.jsx b/src/lib/review/components/CustomerReviews.jsx
index a6e697f0..6ca0fa7b 100644
--- a/src/lib/review/components/CustomerReviews.jsx
+++ b/src/lib/review/components/CustomerReviews.jsx
@@ -3,16 +3,37 @@ import MobileView from '@/core/components/views/MobileView';
 import Image from 'next/image';
 import { Swiper, SwiperSlide } from 'swiper/react';
 import { Autoplay } from 'swiper';
+import { useEffect, useState } from 'react';
 
 const { useQuery } = require('react-query');
 const { getCustomerReviews } = require('../api/customerReviewsApi');
 
 const CustomerReviews = () => {
-  const { data: customerReviews } = useQuery(
+  const [data, setData] = useState(null);
+
+  useEffect(() => {
+    const localData = localStorage.getItem('Homepage_customerReviews');
+    if (localData) {
+      setData(JSON.parse(localData));
+    }
+  },[])
+
+
+  const { data: fetchCustomerReviews } = useQuery(
     'customerReviews',
-    getCustomerReviews
+    getCustomerReviews,{
+      enabled: !data,
+      onSuccess: (data) => {
+        if (data) {
+          localStorage.setItem('Homepage_customerReviews', JSON.stringify(data));
+          setData(data);
+        }
+      }
+    }
   );
 
+  const customerReviews = data
+
   return (
     <div className='px-4 sm:px-0'>
       <h1 className='font-semibold text-[14px] sm:text-h-lg mb-4'>
-- 
cgit v1.2.3

