0.8.3 • Published 5 years ago

sweetalert2-react v0.8.3

Weekly downloads
3,159
License
MIT
Repository
github
Last release
5 years ago

sweetalert2-react

npm version Build status Test coverage Downloads

Declarative SweetAlert in React

Introduction

This is a React SweetAlert wrapper for https://github.com/limonte/sweetalert2

Install

$ npm install sweetalert2-react

Usage

import React, { Component } from 'react';
import SweetAlert from 'sweetalert2-react';

// ...

render() {
  return (
    <div>
      <button onClick={() => this.setState({ show: true })}>Alert</button>
      <SweetAlert
        show={this.state.show}
        title="Demo"
        text="SweetAlert in React"
        onConfirm={() => this.setState({ show: false })}
      />
    </div>
  );
}

Since 0.6, you can wrap your own sweetalert2 (swal) instance:

import React, { Component } from 'react';
import { withSwalInstance } from 'sweetalert2-react';
import swal from 'sweetalert2';

const SweetAlert = withSwalInstance(swal);

// ...

render() {
  return (
    <div>
      <button onClick={() => this.setState({ show: true })}>Alert</button>
      <SweetAlert
        show={this.state.show}
        title="Demo"
        text="SweetAlert in React"
        onConfirm={() => this.setState({ show: false })}
      />
    </div>
  );
}

Tests

Tests were not updated to support sweetalert2. PRs are welcome.

License

MIT © C.T. Lin

0.8.3

5 years ago

0.8.2

5 years ago

0.8.1

5 years ago

0.8.0

5 years ago

0.7.2

6 years ago

0.7.1

6 years ago

0.7.0

6 years ago

0.6.0

6 years ago

0.5.0

7 years ago

0.4.10

7 years ago