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

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];
主站蜘蛛池模板: 赣州市| 阿拉善左旗| 潢川县| 名山县| 塔城市| 吉林市| 鹿邑县| 马龙县| 大兴区| 青海省| 开鲁县| 土默特右旗| 乐清市| 黔南| 濮阳市| 石首市| 芮城县| 饶阳县| 丘北县| 宜丰县| 区。| 兴隆县| 海南省| 石泉县| 海南省| 米林县| 邢台县| 永和县| 扎鲁特旗| 绥芬河市| 潮安县| 天镇县| 云南省| 长治市| 晋城| 长海县| 沙坪坝区| 孟连| 河曲县| 抚宁县| 六安市|