-
Notifications
You must be signed in to change notification settings - Fork 0
Нягу Никита #16
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
base: main
Are you sure you want to change the base?
Нягу Никита #16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const [isLoading, setLoadingState] = useState(false); | ||
const [countUsedKeys, setCountUsedKeys] = useState(0); | ||
|
||
const toggleLoading = useCallback(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Удалить toggleLoading
}, [isLoading]); | ||
|
||
const incrementUsedKeys = () => { | ||
setCountUsedKeys((prevValue) => prevValue++); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
++prevValue
} | ||
|
||
const decrementUsedKeys = useCallback(() => { | ||
setCountUsedKeys((prevValue) => prevValue--); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--prevValue
setLoadingState(!isLoading); | ||
}, [isLoading]); | ||
|
||
const incrementUsedKeys = () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
добавить useCallback
setCountUsedKeys((prevValue) => prevValue--); | ||
}, []); | ||
|
||
const addKey = useCallback(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
убрать useCallback
{keys.length && ( | ||
<div className="keys"> | ||
{keys.map((key) => ( | ||
<Key |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
key={key}
{keys.map((key) => ( | ||
<Key | ||
value={key} | ||
removeKey={removeKey(key)} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removeKey={removeKey}
); | ||
}; | ||
|
||
export function Key({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
добавить memo
[incrementUsedKeys, isUsed, toggleLoading] | ||
); | ||
|
||
useEffect(async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
убрать async
); | ||
|
||
useEffect(async () => { | ||
return async () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Подход удаления на сервер результатом демонтирования технически допустим, но является антипаттерном, поэтому всю логику удаления ключа необхидмо описать в одном месте. Убрать useEffect
No description provided.