Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: bug that the Undo button still exist after tap it. #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/components/App/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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') || [];
Expand Down Expand Up @@ -40,6 +40,7 @@ const App = () => {

const handleUndo = () => {
setState(getData('lastState'));
removeLastState();
};

return (
Expand Down Expand Up @@ -71,8 +72,8 @@ const App = () => {
))}
</>
) : (
<div className='center white-text'>No log found</div>
)}
<div className='center white-text'>No log found</div>
)}
</div>
</div>
{getData('lastState') !== null ? (
Expand All @@ -82,8 +83,8 @@ const App = () => {
</button>
</div>
) : (
''
)}
''
)}
</div>
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions src/helpers/localStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
}
}