Skip navigation
⚛️ React tip: Use a custom hook to handle array states in your components ↓
0:00 / 0:33

⚛️ React tip: Use a custom hook to handle array states in your components ↓

George Moller

@_georgemoller118K followers

Visit on X
1,433 likesDownloadOriginal post

171,103 views

⚛️ React tip: Use a custom hook to handle array states in your components ↓

11 Comments

Comments from the original post on X (Twitter)

  • George Moller's profile picture

    @_georgemoller

    I've been working professionally with React for more than 8 years and I compiled all my knowledge into 100+ infographics and 50+ video animations just like this one. Check them out ↓

    13 likes

  • Jose Monge's profile picture

    @josemongedev

    Do you think if you would add more methods then maybe it would be worth trying trying something like useReducer instead?

    3 likes

  • George Moller's profile picture

    @_georgemoller

    If the logic get's more complex then yes. useState uses useReducer internally and it has a better API for a bit more complex use cases (e.g. when you need a more fine grained control over how your state changes).

    2 likes

  • Pavel Romanov's profile picture

    @pavl_ro

    Do you think it is worth renaming the "add" function to "push"? It is doing the same thing as the "push" method of the array.

    3 likes

  • George Moller's profile picture

    @_georgemoller

    Don't really have a strong opinion about that one, I think it's worth doing it yes to keep consistency with array helper methods.

    1 like

  • Wilson Hou's profile picture

    @itswilsonhou

    how do you do these animations 🤯

    3 likes

  • George Moller's profile picture

    @_georgemoller

    I use keynote Wilson! :)

    2 likes

  • Rohan.dev's profile picture

    @rohan_webdev

    This is good way to handle aarays 😊🙌💯 Good explanation As always , George ✨

    3 likes

  • Enrique Moreno's profile picture

    @enriquemoreno

    Oh, wow! I have used this pattern so many times. How did I not come up with this idea?! Thank you!

    3 likes

  • Akhil 17's profile picture

    @ak_h_il_17

    Nice tip George 👍

    2 likes

  • George Moller's profile picture

    @_georgemoller

    Thank Akhil! glad you liked it!

    1 like