summaryrefslogtreecommitdiff
path: root/src/lib/review
diff options
context:
space:
mode:
authortrisusilo48 <tri.susilo@altama.co.id>2024-10-08 14:56:00 +0700
committertrisusilo48 <tri.susilo@altama.co.id>2024-10-08 14:56:00 +0700
commitf09a72f90c049b5e1a8478f737062a24d9c7a3df (patch)
tree0184463ded590abe8e3f6d79036ef7dc33245e2a /src/lib/review
parentb5d65791b662f4827f5a420f62e32f71f5252cff (diff)
cache localstorage
Diffstat (limited to 'src/lib/review')
-rw-r--r--src/lib/review/components/CustomerReviews.jsx25
1 files changed, 23 insertions, 2 deletions
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'>