- 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];
推薦閱讀
- Magento 2 Theme Design(Second Edition)
- ASP.NET Core Essentials
- Python測試開發入門與實踐
- Full-Stack Vue.js 2 and Laravel 5
- 精通網絡視頻核心開發技術
- HTML5+CSS3網站設計基礎教程
- Hands-On Microservices with Kotlin
- 零基礎學Python網絡爬蟲案例實戰全流程詳解(高級進階篇)
- 學習正則表達式
- 移動互聯網軟件開發實驗指導
- RubyMotion iOS Develoment Essentials
- Web前端開發技術:HTML、CSS、JavaScript
- Flink入門與實戰
- 分布式數據庫HBase案例教程
- Java EE 7 Development with WildFly