This library offers a way to use Alert.alert()
with a side-effect in a react-native app using redux & redux-observable.
redux-observable version | Supporting redux-observable-rn-alert version |
---|---|
< 1.0.0 | 0.1.3 |
>= 1.0.0 | >= 0.1.4 |
yarn add redux-observable-rn-alert
or
npm i redux-observable-rn-alert --save
in the root epic, add alertEpic
.
import { combineEpics } from 'redux-observable'
import { alertEpic } from 'redux-observable-rn-alert'
export const rootEpic = combineEpics(
// ..
alertEpic,
)
You can show an alert by calling the action. Also, you can pass actions that are called when buttons are pressed.
import { AlertActions } from 'redux-observable-rn-alert'
dispatch(
AlertActions.alert({
title: 'foo',
message: 'bar',
buttons: [
{
text: 'baz',
onPressAction: { type: 'BAZ', payload: { qux: 'qux' } },
},
],
options: {
// below are only for Android
cancelable: true,
onDismissAction: { type: 'QUX', payload: { qux: 'qux' } },
},
type: '',
}),
)
Basically, the payload attributes of AlertActions.alert
follow the attributes of Alert.alert()
.
below are the interface and differences from the attributes of Alert.alert()
.
NAME | TYPE | REQUIRED | DIFFERENCE |
---|---|---|---|
title | string |
Yes | Nothing |
message | string |
No | Nothing |
buttons | Array<{ text?: string, onPressAction?: Action, style?: string }> |
No | onPressAction corresponds to onPress of Alert.alert() |
options | { cancelable?: boolean, onDismissAction?: Action } |
No | onDismissAction corresponds to onDismiss of Alert.alert() |
type | string |
No | Nothing |