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

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);
...
}
主站蜘蛛池模板: 高邑县| 思茅市| 土默特左旗| 阜康市| 红河县| 五大连池市| 扶风县| 四川省| 游戏| 巍山| 绥阳县| 平塘县| 湖南省| 金塔县| 巴楚县| 井陉县| 馆陶县| 泊头市| 涞源县| 弥勒县| 望谟县| 山西省| 通渭县| 白城市| 织金县| 鄂伦春自治旗| 邢台县| 盐津县| 普陀区| 塘沽区| 饶平县| 嘉荫县| 甘德县| 鸡西市| 合江县| 奇台县| 鱼台县| 乐都县| 卓尼县| 应用必备| 长宁县|