- 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);
...
}
推薦閱讀
- LabVIEW 2018 虛擬儀器程序設計
- 大學計算機基礎實驗教程
- 深度學習經(jīng)典案例解析:基于MATLAB
- Android Development with Kotlin
- 征服RIA
- Learning ELK Stack
- concrete5 Cookbook
- Mastering Xamarin.Forms(Second Edition)
- Xcode 6 Essentials
- Arduino Wearable Projects
- Learning iOS Security
- Learning Jakarta Struts 1.2: a concise and practical tutorial
- PowerDesigner 16 從入門到精通
- Visual Basic程序設計實驗指導及考試指南
- 算法精解:C語言描述