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-notification

v0.0.1

Published

The simplest way to implement a notiffication system in your React-Redux app

Downloads

19

Readme

react-redux-notification

The simplest way to implement a notification system in your React-Redux app

Installation

npm install --save react-redux-notification

Getting started

CSS

Webpack:

import 'react-redux-notification/src/styles/notifications.css';

Other

<link rel="stylesheet" type="text/css" href="path/to/notifications.css">

Middleware

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import App from './my_app';
import { createStore, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import {notificationsMiddleware} from 'react-redux-notification'
import rootReducer from './my_reducer';

const store = createStore(
    rootReducer,
	applyMiddleware(notificationsMiddleware),

	);

ReactDOM.render(
	<Provider store={store}>
		<App />
	</Provider>
	, document.querySelector('.container'));

Reducer

import { combineReducers } from 'redux';
import { notificationsReducer } from '../src'

const rootReducer = combineReducers({
    notificationsReducer,
});

export default rootReducer;

Using the library

Notifications container

First, add the notifications container in your main component:

import React, { Component } from 'react';
import { Notifications } from 'react-redux-notification'

class MainComponent extends Component {
  render () {
    return (
      <div>
        //.....
        <Notifications duration={1000}/>
      </div>
    )
}
//...

Notification container Props

| Name | Type | Default | Required | |------|------|---------|----------| | duration | number | 3000 | false |

  • duration: Time in ms each single notification will be rendered before disappearing

Actions

Adding a single notification

You can add a notification calling the addNotification action:

import React, { Component } from 'react';
import { Notifications } from 'react-redux-notification';
import { addNotification } from 'react-redux-notification/actions';

class MainComponent extends Component {
  
  addNotification () {
    const notificationPayload = {
            text: 'A notification Message',
        };
        
    this.props.addNotification(notificationPayload)
 }
 
  render () {
    return (
      <div>
        <button onClick={this.addNotification.bind(this)}
        //.....
        <Notifications duration={1000}/>
      </div>
    )
}
//...

Or just add the notifiaction key to any other action you are dispatching, and the library middleware will take care of the rest:

// Some random action in your app

exports function doSomeStuff () {
  type: 'doSomeStuff',
  notification: {
    text: 'Stuff done'
}

Single notification Props

| Name | Type | Default | Required | |------|------|---------|----------| | message | string | None | true | | className | string | Default styles | false | | unique | boolean | false | false | | type | string | None | false |

  • message: Text message to be rendered.
  • className: Class name to be applied to this specific notification. The library comes with an error class to render error like notifications.
  • unique: If true, it will check if a notification of the same "type" exists and if it does, will replace it instead of stacking it.
  • type: Related to the unique props, group related notifications of the same type if you don't want them to stack.

Clearing all notifications

Call clearAllNotifications action to clear all current notifications:

import React, { Component } from 'react';
import { Notifications } from 'react-redux-notification';
import { clearAllNotifications } from 'react-redux-notification/actions';

class MainComponent extends Component {
  
  clearAllNotifications () {
    this.props.clearAllNotifications()
 }
 
  render () {
    return (
      <div>
        <button onClick={this.clearAllNotifications.bind(this)}
        //.....
        <Notifications duration={1000}/>
      </div>
    )
}
//...

Demo

Check the demo folder for an example