From ae0f75d48261ba2057dc0dd4492708f1e6e06522 Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Fri, 18 Oct 2024 11:35:57 +0700
Subject: <iman> get data from local based use effect

---
 src/lib/pengajuan-tempo/component/PengajuanTempo.jsx | 18 ++++++++++--------
 1 file changed, 10 insertions(+), 8 deletions(-)

(limited to 'src/lib/pengajuan-tempo/component/PengajuanTempo.jsx')

diff --git a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
index bdd6e6ef..2c10b1d6 100644
--- a/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
+++ b/src/lib/pengajuan-tempo/component/PengajuanTempo.jsx
@@ -72,6 +72,16 @@ const PengajuanTempo = () => {
     validate();
     validateKontakPerson();
   }, []);
+  useEffect(() => {
+    const cachedData = getFromLocalStorage(stepLabels[currentStep]);
+    console.log('cachedData prev button', cachedData);
+    if (cachedData) {
+      // const formData = JSON.parse(cachedData);
+      Object.keys(cachedData).forEach((key) => {
+        updateForm(key, cachedData[key]);
+      });
+    }
+  }, [currentStep]);
   const goToNextStep = () => {
     if (!isFormValid) {
       setNotValid(true);
@@ -92,14 +102,6 @@ const PengajuanTempo = () => {
   };
 
   const goToPreviousStep = () => {
-    const cachedData = getFromLocalStorage(stepLabels[currentStep - 1]);
-    console.log('cachedData prev button', cachedData);
-    if (cachedData) {
-      // const formData = JSON.parse(cachedData);
-      Object.keys(cachedData).forEach((key) => {
-        updateForm(key, cachedData[key]);
-      });
-    }
     setCurrentStep((prev) => (prev <= 0 ? prev : prev - 1));
   };
 
-- 
cgit v1.2.3

