1.0.2 • Published 5 years ago

context-notification v1.0.2

Weekly downloads
3
License
MIT
Repository
github
Last release
5 years ago

context-notification

A global notification wrapper for react-toastify built with the React Context API

NPM JavaScript Style Guide

Install

npm install --save context-notification
yarn add context-notification

Setup

import React from 'react';
import { NotificationProvider } from 'context-notification';
import ReactDOM from 'react-dom';
import App from './App';


ReactDOM.render(<NotificationProvider><App /></NotificationProvider>, document.getElementById('root'))

Usage: Via the Consumer

import React, { Component } from 'react';
import { Notifier } from 'context-notification';


export default class App extends Component {
    render() {
        return (
            <div>
                <Notifier>
                    {({ notifySuccess, notifyFailure }) => {
                        notifySuccess({ position: 'top-left' });

                        notifyFailure();

                        return (
                            <div style={{ width: 640, margin: '15px auto' }}>
                                <h1>Hello React</h1>
                            </div>
                        );
                    }}
                </Notifier>
            </div>
        )
    }
}

Usage: Via the HOC

import React, { Component } from 'react';
import { withNotifier } from 'context-notification';


class App extends Component {
    render() {
        const { notifySuccess, notifyFailure } = this.props;

        notifySuccess({ position: 'top-left' });

        notifyFailure();

        return (
            <div style={{ width: 640, margin: '15px auto' }}>
                <h1>Hello React</h1>
            </div>
        )
    }
}

export default withNotifier(App);

License

MIT © AwoyoToyin

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago