官术网_书友最值得收藏!

Object and array destructuring

This book makes liberal use of destructuring techniques in an effort to keep the code base as concise as possible. As an example, object destructuring generally happens for function parameters:

const handleSelectBoxChange = ({ target: { value, name } }) => {
...
};

This is equivalent to saying this:

const handleSelectBoxChange = ({ target: { value, name } }) => {
const target = event.target;
const value = target.value;
const name = target.name;
...
};

Return values can also be destructured in the same way. More frequently, you’ll see return values destructured. This happens with the useState hook:

const [customer, setCustomer] = useState({});

This is equivalent to:

const customerState = useState({});
const customer = customerState[0];
const setCustomer = customerState[1];
主站蜘蛛池模板: 丰都县| 鹰潭市| 肥东县| 舟山市| 图木舒克市| 铅山县| 互助| 大关县| 黄冈市| 河北省| 巴楚县| 沁阳市| 平安县| 邵武市| 南汇区| 辽阳市| 平谷区| 东兴市| 井冈山市| 砀山县| 红安县| 甘肃省| 夏邑县| 金塔县| 上虞市| 尖扎县| 姚安县| 建阳市| 光山县| 九寨沟县| 彭阳县| 岳普湖县| 太湖县| 永川市| 义乌市| 晋江市| 瑞金市| 乐平市| 达拉特旗| 光泽县| 和硕县|