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

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];
主站蜘蛛池模板: 普宁市| 建瓯市| 洛宁县| 新乐市| 白朗县| 嘉祥县| 尚志市| 平南县| 博罗县| 黔西县| 临猗县| 铜山县| 清流县| 吴忠市| 饶阳县| 扶风县| 赣州市| 丹东市| 定南县| 福清市| 太谷县| 凤山市| 西华县| 永安市| 永吉县| 抚顺市| 山东省| 友谊县| 陵水| 大城县| 竹溪县| 罗山县| 太湖县| 海安县| 大足县| 南平市| 准格尔旗| 高要市| 萝北县| 广安市| 稷山县|