Betrachten Sie redux-notifications. Es ist eine reine Redux-Lösung ohne die Verwendung von refs
. Die Dokumentation ist ein wenig veraltet, aber das hat für mich funktioniert (die Änderung ist die Aktionen).
Sie fügen die <Notifs />
Komponente an die Wurzel des Projekts:
import { Provider } from 'react-redux'
import { Notifs } from 'redux-notifications';
<Provider store={store}>
<div>
// ... other things like router ...
<Notifs />
</div>
</Provider>
die die notifReducer
an Ihrer Basis Minderer hinzufügen:
import { createStore, combineReducers } from 'redux'
import { reducer as notifReducer } from 'redux-notifications';
combineReducers({
notifs: notifReducer,
// ... more reducers here ...
})
Und dann die in Aktionen verwenden errichtet Benachrichtigungen versenden:
import { actions } from 'redux-notifications';
action.notifSend({
message: "I am a notification",
kind,
id: 1234,
dismissAfter: 2000
})(dispatch)
Ich bin mir nicht sicher, was Sie fragen. –
Ich benutze react-redux-toastr und es funktioniert gut für mich. Es ist der Demo in react-notify sehr ähnlich. – Jaked222