🍫 React Snackbar Alert

Getting Started

Prerequisites

React Snackbar Alert uses the Context API and Hooks. This means it requires React 16.8.0 or newer.

This package requires react, react-dom, and styled-components to be installed in your project.

$ npm install --save react react-dom styled-components

Install the package

$ npm install --save react-snackbar-alert

Add to your app

  • Import the SnackbarProvider component and the wrapComponent helper
  • Wrap your entire application in the SnackbarProvider and pass any configuration to it
  • To create snackbars from a component, wrap it via the wrapComponent helper. This will give it a createSnackbar prop.
  • Call createSnackbar to create snackbars

Example usage

import React from 'react';

import { SnackbarProvider, wrapComponent } from 'react-snackbar-alert';

export default function BaseExample() {
  return (
    <SnackbarProvider>
      <Container />
    </SnackbarProvider>
  );
}

const Container = wrapComponent(function({ createSnackbar }) {
  function showSnackbar() {
    createSnackbar({
      message: 'Hello Snackbar!'
    });
  }

  return (
    <div>
      <button onClick={showSnackbar}>Show Snackbar</button>
    </div>
  );
});