Skip to content

Commit

Permalink
add deleted file
Browse files Browse the repository at this point in the history
  • Loading branch information
gabriellsh committed Dec 7, 2023
1 parent 86cdeee commit 781af15
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions apps/meteor/client/hooks/useFileInput.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useRef, useEffect } from 'react';
import type { AllHTMLAttributes } from 'react';

export const useFileInput = (props: AllHTMLAttributes<HTMLInputElement>) => {
const ref = useRef<HTMLInputElement>();

useEffect(() => {
const fileInput = document.createElement('input');
fileInput.setAttribute('style', 'display: none;');
Object.entries(props).forEach(([key, value]) => {
fileInput.setAttribute(key, value);
});
document.body.appendChild(fileInput);
ref.current = fileInput;

return (): void => {
ref.current = undefined;
fileInput.remove();
};
}, [props]);

return ref;
};

0 comments on commit 781af15

Please sign in to comment.