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
[![npm version][npm-image]][npm-url] [![Downloads][downloads-image]][downloads-url]
Declarative SweetAlert in React
Introduction
This is a React SweetAlert wrapper for https://github.com/alex-shamshurin/sweetalert2-react
Install
$ npm install react-sweetalert2
Usage
import React, { Component } from 'react';
import SweetAlert from 'react-sweetalert2';
// ...
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 'react-sweetalert2';
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