schiehll / react-alert

alerts for React
MIT License
608 stars 98 forks source link

Making an alert from a Redux action? #84

Closed LarryKlugerDS closed 6 years ago

LarryKlugerDS commented 6 years ago

Thank you and congratulations on the project, it is great!

A question: I want one of my Redux actions to show an alert.

Currently, my Redux action sets a Redux property, then a component, in its componentWillReceiveProps method:

  1. Sees the updated property and calls this.props.alert.show
  2. Then it dispatches a Redux action to reset the property. (If it doesn't reset the property then there is an infinite loop.)

This is all working fine, but is there a more direct way for an action to call alert.show?

Many thanks, Larry

schiehll commented 6 years ago

Hey @LarryKlugerDS,

So you are actually looking for a way to show an alert based on a prop update.

I would recommend you to do it in the componentDidUpdate lifecycle (the way you are doing it also works, but componentWillReceiveProps is not recommended anymore, see here).

Hope it helps!