How To Pass Event From Redux To React? How To Pass Event From Redux To React? reactjs reactjs

How To Pass Event From Redux To React?


Suppose you want to use the blink thing to show when something increases, you can simply keep a counter in your state and in your component's internal state keep the previous value. When it changes, blink and save the new value.

In other words, derive your desired event information from state changes you care about.

It is totally fine to use internal state for this sort of transient behavior, that is what it is for.


Imagine CSS transitions are implementation detail and you don't expose methods on components. (You usually shouldn't anyway.)

How would that be driven by props only? I'd imagine by a boolean prop isBlinking. This is what you can keep in Redux state if you wish so. Have an action creator that dispatches START_BLINK and STOP_BLINK after some milliseconds.

Or you can avoid using Redux for this and call method imperatively from parent component.


There's no "restart" in CSS animation, but you can specify iteration count to be infinite, which seems like it would solve your issue without involving Redux at all, other than perhaps toggling the .blinking class on or off depending on of you want it to blink or not.

@keyframes blink {  0% { opacity: 0; }  50% { opacity: 1}  100% { opacity: 0; }}.blinking{    animation-name: blink;    animation-duration: 1s;    animation-iteration-count:infinite;}