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

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);
...
}
主站蜘蛛池模板: 金沙县| 黑山县| 台江县| 廉江市| 托克托县| 莲花县| 武陟县| 锦屏县| 通山县| 手游| 阳山县| 遂川县| 余江县| 峨边| 古浪县| 宁国市| 嘉兴市| 安达市| 洛隆县| 肃宁县| 当雄县| 和硕县| 张家港市| 乐业县| 南投市| 肃北| 美姑县| 榆社县| 香格里拉县| 武强县| 阳高县| 湖北省| 饶平县| 乌拉特中旗| 鄯善县| 若羌县| 奉新县| 达拉特旗| 黑龙江省| 新津县| 合川市|