npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-redux-alerts

v1.5.8

Published

A lightweight library for creating keyed alerts in a Redux app

Downloads

232

Readme

#react-redux-alerts

React Redux Alerts is redux based alert system designed for creating resuable alerts across your application. It consists of two things: a redux reducer and a React higher order component to keep track of when your alert is to render.

Installation

Simply run npm i react-redux-alerts --save to add to your project.

Getting started with react-redux-alerts

###Step 1 The first thing to do is mount the 'react-redux-alerts' reducer to Redux. This only has to be done at startup. Make sure it's mounted to the alerts key.

import { createStore, combineReducers } from 'redux';
import { reducer as alertsReducer } from 'react-redux-alerts';

const reducers = {
    alerts: alertsReducer
};

const reducer = conbineReducer(reducers);
const store = createStore(reducer);

###Step 2 Decoreate your alert component with createAlert(). This will provide your component with two props: message and close(). The first prop is passed in when the createAction is called and the second is a function that can be called from within your component to dimiss it.

// Alert.js

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

const MyAlert = ({message, close}) => (
    <div className='myAlert'>
        {message}
        <button onClick={close}> Click to Dismiss me </button>
    </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. To show the notification, simply dispatch the createAlert action with two arguments: the alertName and the alertMessage. To close, simply call the dismissAlert action with the correct key.

// 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', 'My Alert Message')}
                    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);