Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
react-sweetalert2
Advanced tools
Readme
$ npm i react-sweetalert2
or
$ yarn add react-sweetalert2
import React, { useState } from 'react';
import SweetAlert2 from 'react-sweetalert2';
export default function App(){
const [swalProps, setSwalProps] = useState({});
return (
<div>
<button onClick={() => {
setSwalProps({
show: true,
title: 'Basic Usage',
text: 'Hello World',
});
}}>
Open
</button>
<SweetAlert2 {...swalProps} />
</div>
);
}
import React, { Component } from 'react';
import SweetAlert2 from 'react-sweetalert2';
export default class App extends Component{
constructor(){
super();
this.state = {
swal: {}
}
}
render() {
return (
<div>
<button onClick={() => {
this.setState({
swal: {
show: true,
title: 'Basic Usage',
text: 'Hello World'
}
});
}}>Alert</button>
<SweetAlert2 {...this.state.swal} />
</div>
);
}
}
withSwal
functionswal
props into Functional Componentimport React from 'react';
import { withSwal } from 'react-sweetalert2';
export default withSwal((props, ref) => {
const { swal, ...rest } = props;
function handleClick(){
swal.fire({
title: 'Example',
text: 'Swal injected',
icon: 'success',
});
}
return (
<button onClick={handleClick}>
Open
</button>
);
});
swal
props into Class Componentimport React from 'react';
import { withSwal } from 'react-sweetalert2';
class ExampleComponent extends Component {
function handleClick(){
this.swal.fire({
title: 'Example',
text: 'Swal injected',
icon: 'success',
});
}
render(){
return (
<button onClick={this.handleClick.bind(this)}>
Open
</button>
);
}
}
export default withSwal(ExampleComponent);
SweetAlert2
componentimport React, { useState } from 'react';
import SweetAlert2 from 'react-sweetalert2';
export default function App(){
const [swalProps, setSwalProps] = useState({});
function handleClick(){
setSwalProps({
show: true,
title: 'Example',
text: 'Hello World',
});
}
return (
<div>
<button onClick={handleClick}>
Alert
</button>
<SweetAlert2 {...swalProps}
didOpen={() => {
// run when swal is opened...
}}
didClose={() => {
// run when swal is closed...
}}
onConfirm={result => {
// run when clieked in confirm and promise is resolved...
}}
onError={error => {
// run when promise rejected...
}}
onResolve={result => {
// run when promise is resolved...
}}
/>
</div>
);
}
swal
prop injectedimport React from 'react';
import { withSwal } from 'react-sweetalert2';
export default withSwal(({ swal }, ref) => (
<button onClick={e => {
swal.fire({
title: 'Example',
text: 'Hello World',
didOpen: () => {
// run when swal is opened...
},
didClose: () => {
// run when swal is closed...
}
}).then(result => {
// when confirmed and promise resolved...
}).catch(error => {
// when promise rejected...
});
}}>
Show Alert
</button>
));
import React, { useState } from 'react';
import SweetAlert2 from 'react-sweetalert2';
export default function App(){
const [swalProps, setSwalProps] = useState({});
function handleClick(){
setSwalProps({
show: true,
title: 'Example'
});
}
return (
<div>
<button onClick={handleClick}>
Alert
</button>
<SweetAlert2 {...swalProps}>
<h1>
Hello World!
</h1>
</SweetAlert2>
</div>
);
}
FAQs
A sweetalert2 wrapper to ReactJS
The npm package react-sweetalert2 receives a total of 5,321 weekly downloads. As such, react-sweetalert2 popularity was classified as popular.
We found that react-sweetalert2 demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.