I am learning React + Redux, and I do not understand the correct way to animate. Let's talk on an example:
For example, I have a list, and I would like to remove items in a click. It is very simple if I do not have animation effects: send a REMOVE_ITEM action on a click, the reducer will remove the item from the store and respond to re-renders html.
Add an add position delete animation on click. Thus, when the user clicks on an item, I want to launch a fancy effect of deleting a position and ... how? I can come up with several ways to do this:
1) In a click, I submit the REMOVE_ITEM action, then the reducer marks the item as goingToBeDeleted in the Store, and then responds to the visualization of this element with the .fancy-dissolve-animation class, and I start the timer to dispatch the second REMOVE_ITEM_COMPLETED action. I do not like this idea because it is not yet clear how to add JS animation here (for example, with TweenMax ), and I start a JS timer to re-render when the CSS animation finishes. That sounds good.
2) I send ITEM_REMOVE_PROGRESS actions with an interval of ~ 30 ms, and some "value" is stored in the repository, which represents the current state of the animation. I donβt like it either, since I need to copy the repository ~ 120 times in ~ 2 seconds of animation (let's say I want a smooth animation of 60 frames per second), and this is just a waste of memory.
3) Make an animation and send REMOVE_ITEM only after the animation finishes. This is the most suitable way that I can think of, but still I would like everything to be changed in the store right after the user has completed the action. For example, an animation can take longer than a few seconds, and REMOVE_ITEM can synchronize with the backend - there is no reason to wait for the animation to finish to make a call to the backend API.
Thanks for reading - any suggestions?