Issue
Can someone explain me what is the meaning of []
in a function parameter, I don't get what the purpose of the []
on [fileEntry]
.
const onDrop = ([fileEntry]: any[]) => {
fileEntry && fileEntry.file(file => processFile(file))
}
Does it convert the fileEntry
to an array? I f yes why that won't work?
const onDrop = (fileEntry) => {
fileEntry = [fileEntry]
fileEntry && fileEntry.file(file => processFile(file))
}
Solution
It's destructuring - the function takes an array as its argument and fileEntry
is the first entry of that array.
Simpler example (JavaScript):
const firstEl = ([el]) => el;
console.log(firstEl([a, b, c]));
Does it convert the fileEntry to an array? I f yes why that won't work?
No, it does the opposite. So the first line of your function is backwards. This is the equivalent of the first bit of code:
const onDrop = (fileEntry) => {
[fileEntry] = fileEntry
fileEntry && fileEntry.file(file => processFile(file))
}
Answered By - JLRishe
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.