I have the following code
let { searchTerm: searchTerm = '' } = this.state;
searchTerm = decodeURIComponent(searchTerm)
Which works, but I was wondering if it was possible to embed the expression (decodeURIComponent call) inside the destructuring like
const { decodeURIComponent(searchTerm) : searchTerm = '' } = this.state;
//or
const { searchTerm = searchTerm ? decodeURIComponent(searchTerm) : '' } = this.state;
But those syntaxes are illegal or plain don't work. Haven't found documentation that shows how to, yet, looking at the grammar, it seems it somehow should work, ie it uses the same "initializer" rule
From this grammar rule http://www.ecma-international.org/ecma-262/6.0/#sec-destructuring-assignment
look at AssignmentElement definition
Then go to http://www.ecma-international.org/ecma-262/6.0/#sec-object-initializer
then look at Initializer definition
Then look at http://www.ecma-international.org/ecma-262/6.0/#sec-assignment-operators