Destructuring assignment docs
handleValueChange = (e) => {
const { target: { id, value } = {} } = e || {};
# some code ....
:=
{}
A variable can be assigned a default, in the case that the value unpacked from the object is const
.
For example:
Here you can seeis used for .In your case, if
iswhile destructuring
undefined
, then an empty object
will be used instead.
const {a = 10, b = 5} = {a: 3};
console.log(a); // 3
console.log(b); // 5
This is needed in cases b
is undefined
or 5
, else we will get an error like:b
Cannot read property 'id' of undefinedtarget
Using undefined
default valuee
handles this scenario:{}
我在研究一个项目时,看到了这样的模式。e
我从来没有见过 undefined
内 null
之后
但我在网上找不到任何文档。这种类型的语法叫什么?它的工作原理是什么?
const { target: { id, value } } = {};
console.log( id, value )
我在研究一个项目的时候,看到这样一种模式:handleValueChange = (e) => { const { target: { id, value }。 } = e