A
A
Anton Izmailov2016-03-03 13:22:02
JavaScript
Anton Izmailov, 2016-03-03 13:22:02

How to properly implement Reducer Notification?

And here I am again with my idiotic questions. I still can't think of an adequate solution for creating an alert component.
It is necessary to create notification's during actions with fields: type, text, time.
Those. alert type, content, and lifetime. How to implement it correctly?
Every time during the action, parse the this.props.layout.notifications array, add another element by push and write it down again? If not, how to proceed in order not to create a new reducer?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Gushchin, 2016-03-03
@iNikNik

Every time I need to trigger a notification event (be it a new notification or a deletion of an old one), I need to fetch the existing this.props.layout.notification array, modify it, and send it back to overwrite

Fundamentally not correct. The reducer should deal with state\data. And you have to tell him what to do and with what through actions.
That is, if you need to add a notification - dispatch an action like
dispatch({
  type: 'ADD_NOTIFICATION',
  payload: { notification: { ... } },
})

Naturally wrapping it all in an action creator.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question