I have a GUI react/redux based app. As part of the view there is a "indicator" react component which I wish to blink, and the blinking is done with a CSS3 animation (animation frames). The indicator.blink()
member function of the react component is called to make the indicator blink (it basically removes the blink class from the DOM element, then adds it again 1ms later, as a hack to get around the fact that there is no "restart" api for a CSS3 animation).
Upon certain actions occurring in the redux framework (they can be thunks if needed), I wish to call this blink()
function in the react view. How best to do this?
It doesn't feel right to have the redux action modify the app state, and then the indicator element bind to one of the state variables as a prop
, since it's not really a state, but an instantaneous event. But I know of no other way to get a redux action to change a react component.
Integrating Redux with a UI You can write Redux apps with React, Vue, Angular, Ember, jQuery, or vanilla JavaScript. That said, Redux was specifically designed to work well with React. React lets you describe your UI as a function of your state, and Redux contains state and updates it in response to actions.
We recommend using the React-Redux hooks API as the default approach in your React components. The existing connect API still works and will continue to be supported, but the hooks API is simpler and works better with TypeScript.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With