( initialValue?: string, )
| 1 | import { useCallback, useLayoutEffect, useRef } from 'react' |
| 2 | |
| 3 | export const useUncontrolledInput = < |
| 4 | T extends { value: string } = HTMLInputElement, |
| 5 | >( |
| 6 | initialValue?: string, |
| 7 | ) => { |
| 8 | const ref = useRef<T>(null) |
| 9 | |
| 10 | useLayoutEffect(() => { |
| 11 | if (initialValue) { |
| 12 | ref.current && (ref.current.value = initialValue) |
| 13 | } |
| 14 | }, []) |
| 15 | |
| 16 | return [ |
| 17 | ref.current?.value, |
| 18 | useCallback(() => ref.current?.value, []), |
| 19 | ref, |
| 20 | ] as const |
| 21 | } |
no outgoing calls
no test coverage detected