Great tutorial! Thank you!
Instead of using useReducer for such a simple use case, you could create a new function that would check the new cursor value before calling hook's setCursor:
useReducer
setCursor
const handleSetCursor = useCallback(newCursor => { const result = newCursor; if (newCursor < 0)... return result; }, [totalPages, cursor])
...alrhough this also looks complicated so I'm not sure what's better.
I'd also rename cursor to page as I'd reserve cursor for GraphQL pagination cursor which is usually not a number but a string.
cursor
page
Sorry for formatting, I'm typing this on my phone w/ autocorrect.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Great tutorial! Thank you!
Instead of using
useReducer
for such a simple use case, you could create a new function that would check the new cursor value before calling hook'ssetCursor
:...alrhough this also looks complicated so I'm not sure what's better.
I'd also rename
cursor
topage
as I'd reservecursor
for GraphQL paginationcursor
which is usually not a number but a string.Sorry for formatting, I'm typing this on my phone w/ autocorrect.