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:
- You might have mismatching versions of React and the renderer (such as React DOM)
- You might be breaking the Rules of Hooks
- 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!