mirror of
https://github.com/transloadit/uppy.git
synced 2026-07-18 00:55:35 +00:00
20 lines
672 B
TypeScript
20 lines
672 B
TypeScript
import type { FileInputFunctions, FileInputProps } from '@uppy/components'
|
|
import { createFileInput } from '@uppy/components'
|
|
import { type ChangeEvent, useMemo } from 'react'
|
|
import { useUppyContext } from './headless/UppyContextProvider.js'
|
|
|
|
type TEvent = Event & ChangeEvent<HTMLInputElement>
|
|
|
|
export function useFileInput(
|
|
props?: FileInputProps,
|
|
): FileInputFunctions<TEvent> {
|
|
const ctx = useUppyContext()
|
|
|
|
const fileInput = useMemo(
|
|
() => createFileInput<TEvent>(ctx, props),
|
|
// We need every value on props to be memoized to avoid re-creating the file input on every render
|
|
[ctx, props?.accept, props?.multiple, props],
|
|
)
|
|
|
|
return fileInput
|
|
}
|