1
Fork 0
mirror of https://github.com/Steffo99/festa.git synced 2024-12-22 22:54:22 +00:00
festa/hooks/useFilePickerState.ts

21 lines
No EOL
447 B
TypeScript

import { ChangeEvent, useCallback, useState } from "react";
type FileState = {
value: string,
file: File | null,
}
export function useFilePickerState() {
const [state, setState] = useState<FileState>({ value: "", file: null })
const onChange = (e: ChangeEvent<HTMLInputElement>) => {
setState({
value: e.target.value,
file: e.target.files![0],
})
}
return { state, onChange }
}