I’d like to use default intermediate values in destructuring like:
const { (form = {}): data = {} } = {};
Any way to assign a default {} to form? Couldn’t find, seems impossible.
>Solution :
You need to take the right syntax for destructuring nested objects and a default value at the end.
const getData = object => {
const { form: { data = {} } = {} } = object;
return data;;
};
console.log(getData({}));
console.log(getData({ form: {} }));
console.log(getData({ form: { data: { foo: 42 } }}));