MCPcopy
hub / github.com/Innei/Shiro / useUncontrolledInput

Function useUncontrolledInput

src/hooks/common/use-uncontrolled-input.ts:3–21  ·  view source on GitHub ↗
(
  initialValue?: string,
)

Source from the content-addressed store, hash-verified

1import { useCallback, useLayoutEffect, useRef } from 'react'
2
3export 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}

Callers 3

ReplyModalFunction · 0.90
ImportMarkdownButtonFunction · 0.90
ContentFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected