fin du refactp
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
'use client'
|
||||
|
||||
import { useState, useCallback } from 'react'
|
||||
|
||||
export function useSecret() {
|
||||
const [secret, setSecret] = useState('')
|
||||
const [secretError, setSecretError] = useState<string | null>(null)
|
||||
const [secretVisible, setSecretVisible] = useState(false)
|
||||
|
||||
const isSecretEmpty = !secret.trim()
|
||||
|
||||
const handleSecretChange = useCallback((value: string) => {
|
||||
setSecret(value)
|
||||
if (secretError) setSecretError(null)
|
||||
}, [secretError])
|
||||
|
||||
const toggleSecretVisible = useCallback(() => {
|
||||
setSecretVisible((v) => !v)
|
||||
}, [])
|
||||
|
||||
const clearSecretError = useCallback(() => {
|
||||
setSecretError(null)
|
||||
}, [])
|
||||
|
||||
return {
|
||||
secret,
|
||||
secretError,
|
||||
secretVisible,
|
||||
isSecretEmpty,
|
||||
setSecret,
|
||||
setSecretError,
|
||||
handleSecretChange,
|
||||
toggleSecretVisible,
|
||||
clearSecretError,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user