mirror of
https://github.com/balzack/databag.git
synced 2025-04-25 19:15:23 +00:00
25 lines
556 B
TypeScript
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 }
|
|
}
|