1.0.2 • Published 6 years ago
context-notification v1.0.2
context-notification
A global notification wrapper for react-toastify built with the React Context API
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