JSFiddle - React, Tailwind, and code Playground
by cormip
HTML
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@8"></script>
JavaScript
Swal.fire({
title: 'Long Running Example',
showCancelButton: true,
confirmButtonText: 'Start',
showLoaderOnConfirm: true,
preConfirm: () => {
return fetch(`//api.github.com/users/${login}`)
.then(response => {
if (!response.ok) {
throw new Error(response.statusText)
}
return response.json()
})
.catch(error => {
Swal.showValidationMessage(
`Request failed: ${error}`
)
})
},
allowOutsideClick: () => !Swal.isLoading()
}).then((result) => {
if (result.value) {
Swal.fire({
title: `${result.value.login}'s avatar`,
imageUrl: result.value.avatar_url
})
}
})