- 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];
推薦閱讀
- Visual Studio 2012 Cookbook
- 深入淺出Electron:原理、工程與實踐
- 深入淺出Spring Boot 2.x
- Visual Basic程序設計教程
- SQL Server與JSP動態網站開發
- HTML5+CSS3+jQuery Mobile APP與移動網站設計從入門到精通
- 并行編程方法與優化實踐
- SwiftUI極簡開發
- Mastering Gephi Network Visualization
- Mastering Android Studio 3
- Web前端開發技術:HTML、CSS、JavaScript
- Java并發實現原理:JDK源碼剖析
- WCF技術剖析(卷1)
- Java自然語言處理(原書第2版)
- Learning Google Apps Script