databag/app/client/web/src/conversation/binaryFile/useBinaryFile.hook.ts
2024-12-14 19:51:20 -08:00

25 lines
556 B
TypeScript

import { useState, useEffect } from 'react'
export function useBinaryFile(source: File) {
const [state, setState] = useState({
name: '',
extension: '',
})
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const updateState = (value: any) => {
setState((s) => ({ ...s, ...value }))
}
useEffect(() => {
const name = source.name.split('.').shift();
const extension = source.name.split('.').pop();
updateState({ name, extension });
}, [source]);
const actions = {
}
return { state, actions }
}