edisonneza / jspdf-invoice-template

PDF template created to generate invoices based on props object. Using jsPDF library.

Home Page:https://edisonneza.github.io/jspdf-invoice-template

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Invalid Hook Call

ephraim888sun opened this issue · comments

I created an arrow function called PdfObject, which loops through an array and calls the jsPDFInvoiceTemplate. However, I also put a use state hook (a hook), and I try to set some state and modify the values. However, I get the
Uncaught Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app

const PdfObject = () => {
const [newState, setNewState] = useState(
{..some value})

array.forEach((item) => {

setNewState(...)

var props = {
  ...
}

//Calls The PDF generation
jsPDFInvoiceTemplate(props)

})
}

I assume that this is a react issue, related to the way how hooks work. But nothing related to the library. Please try to do the setState in another way, using not an arrow function; but for sure google it.

Or upload the code in any online editor and i'll try to help u asap.

I fixed it. Thanks!