Skip to content

Commit

Permalink
fix bag
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanTymoshchuk committed Jun 18, 2023
1 parent 82eb8f5 commit 92552fc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function App() {
const [contacts, setContacts] = useLocaleStorage('contacts', initialContacts);
const [filter, setFilter] = useState('');


const addContact = ({ name, number }) => {
const normalizedName = name.toLowerCase();
const isAdded = contacts.find(
Expand Down
8 changes: 4 additions & 4 deletions src/components/hooks/useLocaleStorage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import { useState, useEffect } from 'react';

export default function useLocaleStorage(key, defaultValue) {
// записуємо у локал сторедж те що користувач вписує , якщо нічого не має то буде значення по дефолту
const [state, setState] = useState(() => {
const [contact, setState] = useState(() => {
return JSON.parse(window.localStorage.getItem(key) ?? defaultValue);
});

useEffect(() => {
// якщо користувач щось вписував то ми відображаємо йому це з локал сторедж
window.localStorage.setItem(key, JSON.stringify(state));
}, [key, state]);
return [state, setState];
window.localStorage.setItem(key, JSON.stringify(contact));
}, [key, contact]);
return [contact, setState];
}

0 comments on commit 92552fc

Please sign in to comment.