All Projects → itinance → redux-saga-rn-alert

itinance / redux-saga-rn-alert

Licence: MIT License
Alert.alert()-Support for side effects with redux-saga in react-native-apps

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to redux-saga-rn-alert

timeoff-server
TimeOff is an application that allows companies' employees to set vacations before they begin taking their time off. Implemented in modern tech stack i.e. Node, Express, MongoDB.
Stars: ✭ 33 (+43.48%)
Mutual labels:  redux-saga, react-redux
auth-with-saga-example
code for https://medium.com/@stepankuzmin/authentication-with-react-router-redux-5-x-and-redux-saga-55da66b54be7
Stars: ✭ 14 (-39.13%)
Mutual labels:  redux-saga, react-redux
Hapi React Hot Loader Example
Simple React Hot Loading example with Hapi Server-side rendering
Stars: ✭ 44 (+91.3%)
Mutual labels:  redux-saga, react-redux
React email editor
This project is experimental! It's my attempt to create visual email template editor using React+Redux+etc... tools stack.
Stars: ✭ 19 (-17.39%)
Mutual labels:  redux-saga, react-redux
rapid-react
A light weight interactive CLI Automation Tool 🛠️ for rapid scaffolding of tailored React apps with Create React App under the hood.
Stars: ✭ 73 (+217.39%)
Mutual labels:  redux-saga, react-redux
React Native App Boilerplate
A simple and scalable boiler plate code for React Native App using React Native Navigation by WiX and Saga .
Stars: ✭ 9 (-60.87%)
Mutual labels:  redux-saga, react-redux
React Login
A client side implementation of authentication using react.js for my blog on medium. This is the second part of my previous blog on how to implement scalable node.js server.
Stars: ✭ 105 (+356.52%)
Mutual labels:  redux-saga, react-redux
React Social Network
Simple React Social Network
Stars: ✭ 409 (+1678.26%)
Mutual labels:  redux-saga, react-redux
Todo Redux Saga
Todo app with Create-React-App • React-Redux • Redux-Saga • Firebase • OAuth
Stars: ✭ 184 (+700%)
Mutual labels:  redux-saga, react-redux
React Native Feature Boilerplate
Feature based Architecture for developing Scalable React Native Apps 🚀 using react, redux, sagas and hooks
Stars: ✭ 139 (+504.35%)
Mutual labels:  redux-saga, react-redux
React Redux Boilerplate
A minimal React-Redux boilerplate with all the best practices
Stars: ✭ 799 (+3373.91%)
Mutual labels:  redux-saga, react-redux
isomorphic-react-redux-saga-ssr
Isomorphic, React, Redux, Saga, Server Side rendering, Hot Module Reloading, Ducks, Code Splitting
Stars: ✭ 19 (-17.39%)
Mutual labels:  redux-saga, react-redux
Soundcloud Redux
SoundCloud API client with React • Redux • Redux-Saga
Stars: ✭ 681 (+2860.87%)
Mutual labels:  redux-saga, react-redux
Typescript Hapi React Hot Loader Example
Simple TypeScript React Hot Loading example with Hapi Server-side rendering
Stars: ✭ 44 (+91.3%)
Mutual labels:  redux-saga, react-redux
Youtube React
A Youtube clone built in React, Redux, Redux-saga
Stars: ✭ 421 (+1730.43%)
Mutual labels:  redux-saga, react-redux
React Redux Hooks Starter
React-redux boilerplate using hooks 🎣
Stars: ✭ 69 (+200%)
Mutual labels:  redux-saga, react-redux
ReactNativeSagaFrame
RN开发(一切尽在代码中)
Stars: ✭ 13 (-43.48%)
Mutual labels:  redux-saga, react-redux
React Native Boilerplate
🚀 Type Based Architecture for developing React Native Apps using react, redux, sagas and hooks with auth flow
Stars: ✭ 375 (+1530.43%)
Mutual labels:  redux-saga, react-redux
React Curd
【React全家桶入门系列文章项目】http://blog.csdn.net/awaw00/article/category/6692955
Stars: ✭ 137 (+495.65%)
Mutual labels:  redux-saga, react-redux
laravel-react-boilerplate
Laravel React Boilerplate with Ant Design, Route-Level Code Splitting, Redux, Sanctum Auth
Stars: ✭ 49 (+113.04%)
Mutual labels:  redux-saga, react-redux

redux-saga-rn-alert

Ever wanted to use Alert.alert() with callbacks within a side-effect or generator function? This library help along!

It allows us to show a typical alert-modal while we can pass callbacks for the user-action the redux-saga-way with yield put() or yield call(). Other side-effects like fork or spawn aren't implemented yet. Feel free to contribute if you need it!

Changelog

V 1.2.6

Nested alerts will be prevented from now on, as soon as one re-enables them calling preventNestedAlerts(false).

Let's say in your code gets another alert() called while the first one is still open. This could result in unwanted and strage effects. Since 1.2.6 we will prevent that a subsequent call to alert() will be appear if another alert is still open.

Installation

yarn add redux-saga-rn-alert

or

npm install redux-saga-rn-alert --save

Setup

In the root reducer add the alert-reducer. For instance:

reducer.js:

import { alertReducer } from 'redux-saga-rn-alert';

const appReducer = combineReducers({
  appStates,
  routes,
  ...
  alertReducer
});

In the root saga spawn the channel watcher:

saga.js

import { watchAlertChannel } from 'redux-saga-rn-alert';

export default function * rootSaga() {
  yield [
    // ... all your sagas here
    spawn(watchAlertChannel),
  ];
}

Usage

The alert-function has the same signature as the official alert-method of react-native.

static alert(title, message?, buttons?, options?) {}

Example 1

Show an alert with 2 Buttons and put some actions:

  const buttons = [
      {text: 'Cancel', style:'cancel', put: {type: ACTIONS.S_CANCEL_EDIT}},
      {text: 'OK', style:'default',call: RouterActions.pop},
  ]

  yield call(alert, 'Error', 'Foobar message', buttons)

In this example an alert-box will be shown with two buttons "Cancel" and "ok". If the user taps on "cancel", a yield put() will be executed with a user-defined action, while "ok" raises a yield call to the pop-method of the Router from react-native-router-flux.

Instead of executing a "plain" function like pop() without any arguments, you can also call a method passing arguments:

Example 2

  const buttons = [
      {text: 'Cancel', style:'cancel', put: {type: ACTIONS.S_CANCEL_EDIT}},
      {text: 'OK', style:'default', call: {method: myMethod, args: {name: '', street: ''}},
  ]

  yield call(alert, 'Error', 'Happy to call alert with callbacks within a generator function', buttons)

Example 3

It is also allowed to pass an array of several side effects:

  const buttons = [
      {text: 'Cancel', style:'cancel', actions:
        [
            {put: {type: ACTIONS.S_CANCEL_EDIT}},
            {call: RouterActions.pop},
        ],
      },
      {text: 'OK', style:'default', call: RouterActions.pop},
  ]

  yield call(alert, 'Error', 'Foobar message', buttons)

In this example, the callback-function of the Cancel-button will first "yield put" an action to our reducers and then call the pop()-method of the router.

IOS Style Support:

iOS

On iOS you can specify any number of buttons. Each button can optionally specify a style, which is one of

  • default
  • cancel
  • destructive

Contribution:

Contributors are welcome! Feel free to submit pull requests or open discussions.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].