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

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);
...
}
主站蜘蛛池模板: 松阳县| 邵阳市| 阿鲁科尔沁旗| 彰化市| 许昌县| 汾西县| 河南省| 呼玛县| 栾城县| 洪雅县| 铜梁县| 威信县| 安阳市| 陆良县| 灵石县| 寿阳县| 淮滨县| 兴安县| 涿州市| 西充县| 巴林右旗| 前郭尔| 南溪县| 延安市| 钟山县| 阿拉善盟| 新野县| 谷城县| 奇台县| 万载县| 修水县| 东丽区| 杭锦旗| 云安县| 武威市| 姜堰市| 大安市| 定陶县| 九江市| 博白县| 延安市|