How to fix this Eslint Use the spread operator instead of '.apply()'

Viewed 5539

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}
        />
    ));
}
1 Answers

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}"
Related