Checking for null for FileTrigger
's onSelect()
callback
#6507
-
For /**
* Handler when a user selects a file.
*/
onSelect?: (files: FileList | null) => void, Under what condition would this be null? A failed upload? No files selected? I ask because in your documentation, you don't check against null: https://react-spectrum.adobe.com/react-aria/FileTrigger.html#example function Example(){
let [file, setFile] = React.useState(null);
return (
<>
<FileTrigger
onSelect={(e) => {
let files = Array.from(e);
let filenames = files.map((file) => file.name);
setFile(filenames);
}}>
<Button>Select a file</Button>
</FileTrigger>
{file && file}
</>
)
} |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The type for typescript |
Beta Was this translation helpful? Give feedback.
The type for typescript
input onChange
always includes null, it doesn't know what type of event it is. I guess we could assert that it's never null for this one, as suggested in this discussion https://www.reddit.com/r/typescript/comments/19dqio6/what_is_the_correct_type_for_input_file_onchange/