Skip to content
Advertisement

React custom hook Pagination “data” is not defined

I have got an API which displays categories of music on the browser and I am trying to create a custom hook for pagination, but I keep getting this error, object is not iterable. enter image description here I am new to custom hooks and could really use some help. Can anyone shed some light on how to fix this?

Custom hook

JavaScript

Pagination component

JavaScript

app.js

JavaScript

Advertisement

Answer

The error is because categoriesPerPage, data, startFrom these three are not defined in your pagination component. However you have passed these properties as prop to Pagination Component but you aren’t accessing them

just destructing those properties from props will work. Add below line before calling usePagination() in your Pagination component. Thank you

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement