diff --git a/src/components/App/App.jsx b/src/components/App/App.jsx index 7cd8035d..66928197 100644 --- a/src/components/App/App.jsx +++ b/src/components/App/App.jsx @@ -5,7 +5,7 @@ import './App.css'; import BmiForm from '../BmiForm/BmiForm'; import Info from '../Info/Info'; import Bar from '../Bar/Bar'; -import { getData, storeData } from '../../helpers/localStorage'; +import { getData, removeLastState, storeData } from '../../helpers/localStorage'; const App = () => { const initialState = () => getData('data') || []; @@ -40,6 +40,7 @@ const App = () => { const handleUndo = () => { setState(getData('lastState')); + removeLastState(); }; return ( @@ -71,8 +72,8 @@ const App = () => { ))} ) : ( -
No log found
- )} +
No log found
+ )} {getData('lastState') !== null ? ( @@ -82,8 +83,8 @@ const App = () => { ) : ( - '' - )} + '' + )} diff --git a/src/helpers/localStorage.js b/src/helpers/localStorage.js index e96f43bc..44c6553f 100644 --- a/src/helpers/localStorage.js +++ b/src/helpers/localStorage.js @@ -17,3 +17,11 @@ export const storeData = (key, item) => { console.error(`Error storing item ${key} to localStorage`, err); } }; + +export function removeLastState(){ + try{ + return localStorage.removeItem("lastState"); + }catch(err){ + console.error(`Error removing lastState from localStorage`) + } +}