- Mastering React Test:Driven Development
- Daniel Irvine
- 165字
- 2021-06-24 14:44:59
Understanding code snippets
A block of code is set as follows:
const handleBlur = ({ target }) => {
const result = required(target.value);
setValidationErrors({
...validationErrors,
firstName: result
});
};
There are two important things to know about the code snippets that appear in this book.
The first is that some code samples show modifications to existing sections of code. When this happens, the changed lines appear in bold, and the other lines are simply there to provide context:
const handleBlur = ({ target }) => {
const validators = {
firstName: required
};
const result = validators[target.name](target.value);
setValidationErrors({
...validationErrors,
[target.name]: result
});
};
The second is that, often, some code samples will skip lines in order to keep the context clear. When this occurs, you’ll see this marked by a line with three dots:
if (!anyErrors(validationResult)) {
...
} else {
setValidationErrors(validationResult);
}
Sometimes this happens for function parameters too:
if (!anyErrors(validationResult)) {
setSubmitting(true);
const result = await window.fetch(...);
setSubmitting(false);
...
}
推薦閱讀
- Java加密與解密的藝術(第2版)
- 數據結構(Python語言描述)(第2版)
- C語言程序設計
- Android Wear Projects
- Geospatial Development By Example with Python
- Python網絡爬蟲技術與應用
- C陷阱與缺陷
- SpringBoot從零開始學(視頻教學版)
- Web Developer's Reference Guide
- SwiftUI極簡開發
- Android高級開發實戰:UI、NDK與安全
- Java并發實現原理:JDK源碼剖析
- Python Social Media Analytics
- C#網絡編程高級篇之網頁游戲輔助程序設計
- Getting Started with the Lazarus IDE