arrays - 如何修复这个 Eslint 使用扩展运算符而不是 '.apply()'
问题描述
我学习反应并且不明白如何解决这个问题。从这个来源
,我查看了这个规则的规则详细信息:
使用扩展运算符而不是 '.apply()'。
但是已经尝试过,但它从来没有重新格式化此代码以符合此规则:
renderPages() {
const { pdf, containerWidth, zoom } = this.state;
const { disableVisibilityCheck } = this.props;
if (!pdf) return null;
const pages = Array.apply(null, { length: pdf.numPages });
return pages.map((v, i) => (
<PDFPage
index={i + 1}
key={`pdfPage_${uniqueId()}`}
pdf={pdf}
containerWidth={containerWidth}
zoom={zoom * INCREASE_PERCENTAGE}
disableVisibilityCheck={disableVisibilityCheck}
/>
));
}
解决方案
该消息建议使用这种表达方式:
const pages = { ...{ length: pdf.numPages }};
例如,以下代码编译:
const somePdf = {
numPages: 10,
pageSize: 'A4',
}
const pages = { ...{ length: somePdf.numPages }};
console.log(JSON.stringify(pages))
// returns "{ length: 10}"
推荐阅读
- shell - 使用 UNIX 将文件名与分隔符连接起来
- python - 如何从文件中创建树状图?
- java - 如何修剪字符串Android中的多行?
- list - Create generic extension to make a deep copy of a List with Data Class
- python - 如何从 MDTextField 获取输入?
- node.js - 反应:如果对象键值也为真,则 defaultChecked 设置为真
- flutter - 在发布 apk 时颤动统一 AR 黑屏并在调试中正常工作
- python - re.finditer() 返回的迭代可迭代对象与在迭代之前将其类型转换为列表之间有什么区别。PYTHON
- git - 如何从 Visual Studio 的主分支中删除分支?
- azure - 推荐的 NameIdFormat 用于在 SAML 中使用用户主体名称 (UPN) 作为 NameId