Giter Site home page Giter Site logo

sheikhg1900 / react-notifier-system-redux Goto Github PK

View Code? Open in Web Editor NEW
2.0 2.0 0.0 105 KB

Indirect redux implementation of "react-notification-system", with edit and remove options. The alternative of "react-notification-system-redux"

Home Page: https://codesandbox.io/s/w7rlxrjv65

JavaScript 100.00%
react notification react-notification notification-system react-notification-system react-notification-system-redux react-notifier-system react-component redux redux-notification

react-notifier-system-redux's Introduction

React Notifier System

npm version Dependency Status devDependency Status Build Status Coverage Status

Redux implementation of react-notifier-system.

Indirect redux implementation of react-notification-system, with edit and remove options.

The alternative of react-notification-system-redux

Screenshot

Installing

npm install react-notifier-system-redux

Using

redux store configuration

import {createStore, combineReducers} from 'redux';
import {reducer as notifications} from 'react-notifier-system-redux';

export function configureStore(initialState = {}) {
  return createStore(
    combineReducers({
      
      // storeKey. You can keep it as you want. Its default value is "notifications" 
      notifications,
      .....,
      ...

    }),
    initialState
  );
}

add react notifier redux component

For optimal appearance, this component must be rendered on a top level HTML element in your application to avoid position conflicts.

import * as React from 'react'
import { Notifier } from 'react-notifier-system-redux'

const App = () => (
  <div>
    {/* optional property [storeKey="notifications"]. storeKey is only required when it is configured other then "notifications". See your store configuration */}
    <Notifier />
  </div>
)

ReactDOM.render(
  React.createElement(App),
  document.getElementById('app')
);

example of dispatching actions

import React from 'react'
import { connect } from 'react-redux'
import { showNotification, clearNotifications, removeNotification } from  'react-notifier-system-redux'

const DispatchigExample = class extends React.Component<{dispatch: func}> {
  dispatchNotificationActions() {
      const { dispatch } = this.props
      dispatch(clearNotifications())

      dispatch(showNotification({
        message: 'Notification 1',
        level: 'error',
        title: 'Notification 1 Title',
        autoDismiss: 0,
        id: 'notification-1',
      }))

      dispatch(showNotification({
        message: 'Notification 2',
        level: 'error',
        title: 'Notification 2 Title',
        autoDismiss: 0,
        id: 'notification-2',
      }))

      dispatch(showNotification({
        message: 'Notification New',
        level: 'error',
        title: 'Notification New Title',
        autoDismiss: 0,
      }))

      // "notification-2" will never be shown as it is removed.
      dispatch(removeNotificationById('notification-2'))
    }

  render() {
    return (
      <div>
        <button onClick={this.dispatchNotificationActions}>Dispatch Notification Actions</button>
      </dev>
    )
  }
}

// connect is used to get dispatch method.
export default connect()(DispatchigExample)

react-notifier-system-redux's People

Contributors

sheikhg1900 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.