Socket
Socket
Sign inDemoInstall

react-redux-alerts

Package Overview
Dependencies
2
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-redux-alerts


Version published
Maintainers
1
Install size
22.6 kB
Created

Readme

Source

#react-redux-alerts

Installation

npm i react-redux-alerts --save

The Gist

A redux based alert system designed for creating resuable alerts across your application.

// Alert.js

import React from 'react';
import { createAlert } from 'react-redux-alerts';

const MyAlert = () => (
    <div>
        This is my custom alert message.
    </div>
);

/** 
 * This is a wrapper method that connects your alert to the store based on a alertName key. This is the unique identifier that will allow you to both show the alert and dismiss the alert. 
 */
export default createAlert({
    alertName: 'myAlert'
})(MyAlert);

This wrapped component can then be pluged into any container that you want the alert to show up in.

// MyContainer.js

import React, { Component, PropTypes } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { actions as alertActions } from 'react-redux-alerts';
import MyAlert from './Alert';

class MyContainer extends Component {
    render() {
        return(
            <div>
                This is my custom container.
                <MyAlert />
                <button onClick={() => this.props.createAlert('myAlert')}
                    Create Alert!
                </button>
                <button onClick={() => this.props.dismissAlert('myAlert')}
                    Dismiss Alert!
                </button>
            </div>
        )
    }
}

function mapDispatchToProps(dispatch) {
  return { alerts: bindActionCreators(alertActions, dispatch) };
}

export default connect(mapStateToProps, mapDispatchToProps)(MyContainer);

Using the react-redux-alert actions, you can dismiss or create notifications by passing the appropriate key to the action.

FAQs

Last updated on 14 Jun 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc