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-snackbar-toast

v1.2.6

Published

Snackbar/Toast Component for react

Downloads

31

Readme

React snackbar/toast component

Find demo here

Installation

npm install --save react-snackbar-toast

or

yard add react-snackbar-toast

Usage

Wrap your application with SnackbarProvider

// App.js
import React from 'react'
import {SnackbarProvider} from 'react-snackbar-toast'
import MessageComponent from './MessageComponent'

export default function App() {
  return (
    <SnackbarProvider>
        <MessageComponent/>
    </SnackbarProvider>
  )
}

Then you can use useSnackbar() hook on any descendant functional component:

// MessageComponent.js
import React from 'react'
import useSnackbar from 'react-snackbar-toast'

export default function MessageComponent() {
  const {addToast} = useSnackbar()

  return (
    <div>
      <button onClick={() => addToast('Snackbar content')}>
        Click to open the Snackbar!
      </button>
    </div>
  )
}

if you are having class component then wrap your component withSnackbar()

import React from 'react'
import { withSnackbar } from 'react-snackbar-toast'
 
class SomeComponent extends React.Component {
  render() {
    const { addToast, removeAllToast } = this.props
 
    return (
      <div>
        <button onClick={() => addToast('This is the content of the Snackbar.')}>
          Click here to open the Snackbar.
        </button>
        <button onClick={removeAllToast}>
          Click here to remove all snackbars.
        </button>
      </div>
    )
  }
}
export default withSnackbar(SomeComponent)

These methods are are returned from useSnackbar() hook in array destructuring syntax:

const {addToast, removeToast, removeAllToast} = useSnackbar()

addToast(node, [options])

    addToast('Hey')
    addToast('<b>Hey</b>')
    addToast('Hey', {autoDismiss: false, type: 'success'})

removeToast(id)

Remove the particular snackbar with returned id from addToast.

    let toastId = addToast('Hey', {autoDismiss: false});
    removeToast(toastId)

removeAllToast()

Remove all active snackbars.

    addToast('Hey', {autoDismiss: false});
    addToast('Hey', {autoDismiss: false});
    removeAllToast()

Options

Options object can be passed to customize the Snackbar. This option can be passed with useSnackbar(node, options):

autoDismissTime:(number) Used to give auto dismissal time for snackbar. By Default it is 3000ms.
                addToast('Hey', {autoDismissTime: 10000});

autoDismiss:(Boolean) To disable auto dismissal of snackbar.
             addToast('Hey', {autoDismiss: false});

icon:(string) To provide custom icon for snackbar. 
      addToast('Hey', {icon: 'http://www.img.com/img});

type:(string) Two types 'success' and 'error'.
      addToast('Hey', {autoDismiss: false, type: 'success'})

className:(string) adds the custom className to snackbar.
      addToast('Hey', {className: 'customClass'})

closeButton:(Boolean) adds the close button to snackbar.
      addToast('Hey', {closeButton: true})

closeIcon:(string) To provide custom icon to close button.
      addToast('Hey, How are you today?', {closeButton: true, closeIcon: 'http://www.img.com/img});
      
component:(ReactNode) We can custom component for snackabr.
            addToast(<somecomponent/>)

retry:(Function) To show retry button in snackbar.
        addToast('something wrong', {autoDismiss: false, type: 'error', retry: () => {//do retry here}} )