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

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];
主站蜘蛛池模板: 赤峰市| 金门县| 利津县| 平谷区| 云和县| 宾阳县| 阿图什市| 扎鲁特旗| 连城县| 吴川市| 内乡县| 集贤县| 通榆县| 平遥县| 太原市| 昌宁县| 西乌珠穆沁旗| 印江| 印江| 从化市| 定南县| 乌拉特中旗| 商丘市| 和林格尔县| 富锦市| 民丰县| 普格县| 自治县| 自治县| 五大连池市| 鄂温| 区。| 柯坪县| 监利县| 大兴区| 噶尔县| 太和县| 南投市| 利辛县| 丹巴县| 伊金霍洛旗|