In the below function, I get the textarea object with the property current
.
Here, nested destructuring works with Start
and End
variables. But current
variable doesn't work.
function someFunction({ current: { selectionStart: Start, selectionEnd: End } }, AppStateSetter) {
// do something with current, Start, and End
}
I think the issue you are facing happens when current is
undefined
.You can try destructing with default value.
If you think you need to access
current
as well, try destructuring inside the function.The first destructuring creates only
Start
andEnd
variables. If you want to createcurrent
as a variable, then you need to declare it again.You can test it on the Babel compiler:
This code:
Gets trasnpiled to:
As you can see,
current
variable is not created.