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

@snackstack/core

v1.3.1

Published

To install the latest stable version with [npm](https://www.npmjs.com/get-npm), run the following command:

Downloads

18

Readme

Installation

To install the latest stable version with npm, run the following command:

npm install @snackstack/core

Or if you're using yarn:

yarn add @snackstack/core

Setup

Once you have installed snackstack, import the SnackProvider and SnackStack component, as well as the SnackManager class.

Instantiate a new instance of the SnackManager class and optionally pass an options object of type SnackManagerOptions to its constructor.

Now that the manager is setup, wrap the SnackProvider around the parts of your application that should be able to manage and display notifications. The newly created SnackManager instance needs to be passed as value to the manager property on the provider.

Place the SnackStack component somewhere below the SnackProvider and specify a component used to render your notifications.

import React from 'react';
import ReactDOM from 'react-dom/client';
+ import { SnackProvider, SnackStack, SnackManager, SnackProps } from '@snackstack/core';

+ const snackManager = new SnackManager({ maxSnacks: 7 });

const root = ReactDOM.createRoot(document.getElementById('root') as HTMLElement);

root.render(
  <React.StrictMode>
+   <SnackProvider manager={snackManager}>
      <App />

+     <SnackStack Component={MyNotification} />
+   </SnackProvider>
  </React.StrictMode>
);

+ const MyNotification = React.forwardRef<unknown, SnackProps>(({ message, offset }, ref) => {
+   return <div ref={ref} style={{ top: offset }}>{message}</div>;
+ });

⚠️ Note: If you are using a custom component, make sure you are forwarding a ref to a native element inside of it.

While this gives you full creative freedom to design your notification component, you might prefer a pre-built solution:

Learn more about displaying notifications

Managing notifications

Once setup, notifications can be managed through the SnackManager. You can either use the instance you previously instantiated or the useSnackManager hook (works only in components rendered below the SnackProvider).

+ import { useSnackManager } from '@snackstack/core';

function App() {
+ const manager = useSnackManager();

  const handleClick = () => {
+   manager.enqueue('A notification');
  };

  return <button onClick={handleClick}>Show notification</button>;
}

Learn more about managing notifications