- Mastering React Test:Driven Development
- Daniel Irvine
- 128字
- 2021-06-24 14:45:00
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];
推薦閱讀
- JavaScript 從入門到項(xiàng)目實(shí)踐(超值版)
- OpenCV for Secret Agents
- Servlet/JSP深入詳解
- Learning ELK Stack
- SQL Server 2016數(shù)據(jù)庫應(yīng)用與開發(fā)
- OpenCV 4計(jì)算機(jī)視覺項(xiàng)目實(shí)戰(zhàn)(原書第2版)
- 時空數(shù)據(jù)建模及其應(yīng)用
- Illustrator CC平面設(shè)計(jì)實(shí)戰(zhàn)從入門到精通(視頻自學(xué)全彩版)
- Delphi開發(fā)典型模塊大全(修訂版)
- Python+Office:輕松實(shí)現(xiàn)Python辦公自動化
- IPython Interactive Computing and Visualization Cookbook
- Visual Basic語言程序設(shè)計(jì)上機(jī)指導(dǎo)與練習(xí)(第3版)
- 程序員面試金典(第6版)
- 輕松學(xué)Scratch 3.0 少兒編程(全彩)
- Implementing Domain:Specific Languages with Xtext and Xtend