/
lizardking
/
react_final
Обзор
Документация
Войти
/
lizardking
/
react_final
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
old
src/shared/ui/ProductCartCounter/hooks/useCount.ts
27 строк
818 B
LizardKing
Initial commit
22 ноя 2025, 15:56
22 ноя 2025, 15:56
0df0d9e
Код
Авторство
О чём код?
import type { ChangeEvent } from 'react' import { useState } from 'react' const MIN_COUNT = 1 const MAX_COUNT = 99 export const useCount = () => { const [count, setCount] = useState(1) const handleCount = (e: ChangeEvent<HTMLInputElement>) => { const newCount = +e.target.value const validCount = newCount > MAX_COUNT ? MAX_COUNT : newCount < MIN_COUNT ? MIN_COUNT : newCount setCount(validCount) } const handleCountMinus = () => { const newCount = count - 1 const validCount = newCount < MIN_COUNT ? MIN_COUNT : newCount setCount(validCount) } const handleCountPlus = () => { const newCount = count + 1 const validCount = newCount > MAX_COUNT ? MAX_COUNT : newCount setCount(validCount) } return { count, handleCount, handleCountMinus, handleCountPlus } }