官术网_书友最值得收藏!

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);
...
}
主站蜘蛛池模板: 洛川县| 凤山县| 周宁县| 延吉市| 晋江市| 阳东县| 吕梁市| 博野县| 科技| 当雄县| 兴仁县| 林甸县| 博乐市| 通化县| 平乡县| 三江| 宁武县| 远安县| 增城市| 大同县| 泸溪县| 济源市| 榆林市| 瓮安县| 科技| 通州区| 屏边| 喀喇| 梧州市| 邵阳县| 六枝特区| 梓潼县| 通渭县| 琼海市| 桑植县| 赞皇县| 临武县| 安塞县| 泰顺县| 湘潭县| 米易县|