Great question actually :)
As a matter of a fact I used the reducer to obtain control on the setCursor and do some validation for it (you can read more about it in details here: dev.to/mbarzeev/creating-a-react-c...)
After the comments here I went a little bit deeper and saw that it can also be done with useState (still not in the most elegant manner), and I updated my hooks package accordingly.
Thanks for the feedback!
According to the React Doc the useReducer is prefer over useState if you have a complex state logic or your next state depends on the previous one. The latter case is pagination.
Unfortunately this is not a good example of using a reducer. It could work for pagination, but you would place the next/previous/set logic inside of the reducer. In this case it's essentially used as useState.
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.
In your hook usePagination, why use a useReducer instead of useState?
Great question actually :)
As a matter of a fact I used the reducer to obtain control on the setCursor and do some validation for it (you can read more about it in details here: dev.to/mbarzeev/creating-a-react-c...)
After the comments here I went a little bit deeper and saw that it can also be done with useState (still not in the most elegant manner), and I updated my hooks package accordingly.
Thanks for the feedback!
According to the React Doc the useReducer is prefer over useState if you have a complex state logic or your next state depends on the previous one. The latter case is pagination.
Unfortunately this is not a good example of using a reducer. It could work for pagination, but you would place the next/previous/set logic inside of the reducer. In this case it's essentially used as useState.