Skip to content

Нягу Никита#16

Open
astrodelete wants to merge 2 commits intomainfrom
interview
Open

Нягу Никита#16
astrodelete wants to merge 2 commits intomainfrom
interview

Conversation

@astrodelete
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown

@ChristmasWoe ChristmasWoe left a 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(() => {
Copy link
Copy Markdown

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++);
Copy link
Copy Markdown

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--);
Copy link
Copy Markdown

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 = () => {
Copy link
Copy Markdown

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 () => {
Copy link
Copy Markdown

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
Copy link
Copy Markdown

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)}
Copy link
Copy Markdown

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({
Copy link
Copy Markdown

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 () => {
Copy link
Copy Markdown

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 () => {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Подход удаления на сервер результатом демонтирования технически допустим, но является антипаттерном, поэтому всю логику удаления ключа необхидмо описать в одном месте. Убрать useEffect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants