JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6760
  • Score
    100M100P100Q125945F
  • License Apache-2.0

SweetAlert2 implementation for ReactJS

Package Exports

  • react-sweetalert2

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-sweetalert2) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

react-sweetalert2

Install

$ npm install react-sweetalert2

Usage

Basic

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

class App extends Component{
    constructor(){
        super();

        this.state = {
            swal: {}
        }
    }

    render() {
        return (
            <div>   
                <button onClick={() => {
                    this.setState({
                        swal: {
                            show: true,
                            text: 'Hello World'
                        }
                    });
                }}>Alert</button>  
                <SweetAlert {...this.state.swal} />
            </div>
        );
    }
}

With Events

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

class App extends Component{
    constructor(){
        super();

        this.state = {
            swal: {}
        }
    }

    render() {
        return (
            <div>   
                <button onClick={() => {
                    this.setState({
                        swal: {
                            show: true,
                            text: 'Hello World',
                        }
                    });
                }}>Alert</button>  
                <SweetAlert {...this.state.swal}
                    onOpen={() => {
                        // code...
                    }}
                    onClose={() => {
                        // code...
                    }}
                />
            </div>
        );
    }
}

With Loader

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

class App extends Component{
    constructor(){
        super();

        this.state = {
            swal: {}
        }
    }

    render() {
        return (
            <div>   
                <button onClick={() => {
                    this.setState({
                        swal: {
                            show: true,
                            showLoading: true,
                            text: 'Loading...',
                        }
                    });
                }}>Alert</button>  
                <SweetAlert {...this.state.swal}/>
            </div>
        );
    }
}