1.3.2 • Published 5 years ago

snackstack v1.3.2

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

snackstack npm.io npm.io npm.io

Easy-to-use extension of Material-UI, which allows the stacking of Snackbar notification messages.

Table of Contents

Installation

MethodCommand
NPMnpm install snackstack
YARNyarn add snackstack

Getting started

Wrap all components, which should be able to enqueue or close Snackbar Notifications, in a SnackProvider:

import { SnackProvider } from 'snackstack';

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

If you're using MuiThemeProvider make sure that you place the SnackProvider inside of it.

withSnacks

The withSnacks HOC injects the enqueueSnack and closeSnack function into your component's props:

import { withSnacks } from 'snackstack';

class ExampleComponent extends React.Component {
  onEnqueueClick = () => {
    const { enqueueSnack } = this.props;

    enqueueSnack({ message: 'Hello World', key: 'key123' });
  };

  onCloseClick = () => {
    const { closeSnack } = this.props;

    closeSnack('key123');
  };

  render() {
    return (
      <div>
        <button onClick={this.onEnqueueClick}>Enqueue</button>
        <button onClick={this.onCloseClick}>Close</button>
      </div>
    );
  }
}

export default withSnacks(ExampleComponent);

useSnacks

The useSnacks Hook returns an array containing the enqueueSnack and closeSnack function:

import { useSnacks } from 'snackstack';

const ExampleComponent = () => {
  const [enqueueSnack, closeSnack] = useSnacks();

  const onEnqueueClick = () => {
    enqueueSnack({ message: 'Hello World', key: 'key123' });
  };

  const onCloseClick = () => {
    closeSnack('key123');
  };

  return (
    <div>
      <button onClick={onEnqueueClick}>Enqueue</button>
      <button onClick={onCloseClick}>Close</button>
    </div>
  );
};

export default ExampleComponent;

If you're unfamiliar with Hooks I suggest this article as an introduction.

Documentation

Not yet available

2.0.0-alpha.0

5 years ago

1.3.2

6 years ago

1.3.1

6 years ago

1.3.0

6 years ago

1.2.0

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

1.0.0-rc1

6 years ago

0.0.14

9 years ago

0.0.13

9 years ago

0.0.12

9 years ago

0.0.11

9 years ago

0.0.10

9 years ago

0.0.9

9 years ago

0.0.8

9 years ago

0.0.7

9 years ago

0.0.6

9 years ago

0.0.5

9 years ago

0.0.4

9 years ago

0.0.3

9 years ago

0.0.2

9 years ago

3.0.4

9 years ago

0.0.1

9 years ago