Reputation: 2836
I learn react and dont understand how to fix this. From this source
I look in the Rule Details for this rule:
Use the spread operator instead of '.apply()'.
But have tried but it's never working to reformate this code to comply with this rule:
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}
/>
));
}
Upvotes: 5
Views: 14668
Reputation: 99
when using eslintrc.json, add "prefer-spread": ["off"]
in rules.
Here are some rules that i use in one of my projects:
"rules": {
"@typescript-eslint/no-this-alias": [
"error",
{
"allowDestructuring": true,
"allowedNames": ["self"]
}
],
"@typescript-eslint/no-empty-function": [
"error",
{
"allow": [
"functions",
"getters",
"setters",
"arrowFunctions",
"methods",
"constructors"
]
}
],
"prefer-spread": ["off"]}
Upvotes: 0
Reputation: 2127
I think that rule is not that important, so if you want you can simply disable the rule by adding this line to your rules in the eslintrc.js
file:
'rules': {
...
'prefer-spread': ['off']
}
Upvotes: 1
Reputation: 6597
The message suggest using this kind of expression:
const pages = { ...{ length: pdf.numPages }};
For instance, the following code compiles:
const somePdf = {
numPages: 10,
pageSize: 'A4',
}
const pages = { ...{ length: somePdf.numPages }};
console.log(JSON.stringify(pages))
// returns "{ length: 10}"
Upvotes: 5