Default Value for Deconstructed Object Parameter
In ES6, you can deconstruct a function’s object parameter to have its properties assigned to local named variables:
function MyComponent({
item: { foo, bar }
}) { ... }
Also in ES6, the properties of the object parameter can have a default value set:
function MyComponent({
item = "LOL"
}) { ... }
TIL: The object parameter can have both destructuring and default values applied to it!
function MyComponent({
item: { foo, bar } = { foo: 1, bar: 2 }
}) { ... }
Written on January 19, 2018 by evanbrodie