Implement Sweet Alerts with React JS
Hi guys! What's going on? This is the time to write another article on React JS. Actually this is not only a React article, but also an article on Sweet Alert. What is this sweet alerts? It's a simple library for including dynamic alerts with animations into our UI. We can easily integrate this into any language, according to their guides. So, today I'm going to explain you the way to implement sweet alerts with React JS.
Usually React JS installs packages from a package manager, to be used in the application. So, most used package manager is NPM as you know. Here I will also use this to install the package.
Create a React app with create-react-app command. If you don't know, visit the below link.
Install Sweet Alert package into it by navigating into the project via terminal/cmd.
npm install sweetalert --save
Then you can import Sweet Alerts as swal, to any React component. This is the way to import.
import swal from 'sweetalert';
When to use these alerts?
In your application, you perform some actions. after an action is successfully performed as expected, you can display an alert to the user to inform it's done. For an example, just think you are going to add a record to database. After successfully adding it to DB, you can show an alert saying that addition was successful..
How to implement?
I'm not going to connect this with a real back-end. You can do it by following the steps I show. Just select a scenario that you are going to save a user to database. In React, I use Axios as the HTTP client to handle data with react. I think it's the most used client and the most easier one to implement.
If you want more details, visit my previous article on axios.Link: https://salitha94.blogspot.com/2018/11/axios-http-client-with-react-js.html
Since axios is a promised based client, after the promise is fulfilled, we can perform displaying sweet alerts..Think of the scenario I told before(data adding scene). How to introduce sweet alerts into this function? Look at below code..
Here, after response has come, alert code has been included. These sweet alerts have several type of messages..They are success, info, error and warning. I have implemented a success message..You can see a green color tick indicating success. Other text shown can be customized.
Success message:
Success message:
Error message:
Warning message:
Info message:
title : Large text shown on the top
text : Small text shown below the top line
icon : Message icon type (success/error/warning/info)
timer : Auto close ability after 2 seconds..change its value as you want
button : Button's availability on bottom down corner. (ok button)
This can be set as a string also, instead of true/false. Then that text will be shown on the button.
buttons : Show multiple buttons on message body. Ex: buttons: [ "ok", "cancel" ]
dangerMode : This is for confirmation messages. When you want to ask are you sure? when this is set as true, color will be red.
When we click on ok, axios will take care of the deletion of any user. I will now show you the way to include this scenario.
Can you see the difference? In this way, we can easily introduce confirming action for a user in our applications. If you want more details, visit here, their official site. I have explained the practical usage of these sweet alerts.
Try to implement this into your UI code! It will be very attractive and informative for user. He or she is well aware of the actions they perform. I think you have got some idea to implement the sweet alerts with React JS and Axios. So, this is all for today. I will come again with another React article!
Good Bye!
Warning message:
Info message:
How to customize Message Body?
As I mentioned, we can change the message content to a some extent. Now I will explain the parameters included in swal.title : Large text shown on the top
text : Small text shown below the top line
icon : Message icon type (success/error/warning/info)
timer : Auto close ability after 2 seconds..change its value as you want
button : Button's availability on bottom down corner. (ok button)
This can be set as a string also, instead of true/false. Then that text will be shown on the button.
buttons : Show multiple buttons on message body. Ex: buttons: [ "ok", "cancel" ]
dangerMode : This is for confirmation messages. When you want to ask are you sure? when this is set as true, color will be red.
Confirmation messages with an action
When you want to display a warning message before user does something very risky, you can sweet alerts in such situations also. An action can be implemented with axios to be completed after confirming by saying "ok".When we click on ok, axios will take care of the deletion of any user. I will now show you the way to include this scenario.
Can you see the difference? In this way, we can easily introduce confirming action for a user in our applications. If you want more details, visit here, their official site. I have explained the practical usage of these sweet alerts.
Try to implement this into your UI code! It will be very attractive and informative for user. He or she is well aware of the actions they perform. I think you have got some idea to implement the sweet alerts with React JS and Axios. So, this is all for today. I will come again with another React article!
Good Bye!
50 Comments
Nice Blog!
ReplyDeleteI've gone through all the sweet alerts that you mentioned with its coding part on Reactjs and I believe that this is the best blog one can learn with. I was looking to hire reactjs development company in India and got your blog.
Thanks for such a great article.
Thank you for your nice comment Synsoft Global :D
DeleteVery Nice Blog ...
ReplyDeleteI have gone through all your sweet alerts .These sweet alerts will help the reactjs web development company. Thank you for sharing this article.
Thank you for your feedback :D Keep in touvh with TechPool!
DeleteI have more information about the Reactjs development company , So here is the list of top 10 ReactJS Development Companies. Thanks for your post . Keep posting .
DeleteYour blog is very informative and gracefully. Your guideline is very good. Thank you Website Development Company in Bangalore | Web Designing Company in Bangalore | Best Web Design Company in Bangalore | Website Design Company in Bangalore
ReplyDeleteThank You Zinavo-Web Design!
DeleteGreat Info! ...Thanks for sharing information with us. If someone wants to know about Taxi Service App and Health Management Software I think this is the right place for you.
ReplyDeleteTaxi Dispatch App | Taxi Service Providers | Safety and Health Management System
Thanks Sathya!
DeleteThank you for useful information. Very Helpful for everyone
ReplyDeleteFull Stack online Training
Full Stack Training
Full Stack Developer Online Training
Full Stack Training in Hyderabad
Full Stack Training in Ameerpet
Full Stack Training Institute
Thanks for your valuable feedback!
DeleteThank you very much Ajish! Will do more...
ReplyDeletevery nice blog...I will definitely follow your blog in future
ReplyDeleteReactJs Online Training
ReactJs Training in Hyderabad
ReactJs Training in Hyderabad
Thank you Ramakrishna!
DeleteGood Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging on react js online training hyderabad
ReplyDeleteThank you Siva!
DeleteTo choose a web design company,you can read the online reviews to know whether the company you hire is reliable and trustworthy or not. Web Development Company in Bangalore | Web Design Company in Bangalore | Website Design Companies in Bangalore | Website Designing Company in Bangalore | Web Designing Company in Bangalore
ReplyDeleteThaks a lot!
ReplyDeleteThank a lot buddy! :D
ReplyDeleteGreetings! Very helpful advice within this article! It is the little changes that produce the largest changes. Many thanks for sharing!
ReplyDeleteReactjs Training in Bagalore
Thank you very much!
DeleteThis comment has been removed by the author.
ReplyDeleteThank for the feedback :D
DeleteBeing a well-recognized React JS Development Company offers reliable website design and website development services for a growing range of businesses across diverse verticals. Their team of expert React JS developers proved a track record by providing custom app development services, high-quality and efficient deliverables based on the client requirement within budget. Hire Top React Native Developers for your ReactJS development project!
ReplyDeleteRead More: Best React JS Development Companies in India
Here are the Top Mobile App Development Companies New York which produce excellent app development services along with additional services and resources that support any business demands.
ReplyDeleteThanks for this. I really like what you've posted here and wish you the best of luck with this blog and thanks for sharing. Reactjs Tutorials Online
ReplyDeleteThank you Micheal :D
DeleteThank you very much :D
ReplyDeleteGlad to hear such comments :D
ReplyDeleteThis is most informative about Js really good content well said above implementations and also this post most user friendly and super navigation to all posts..Thank you so much for giving this information to me.Really you have done great job,There are may person searching about that now they will find enough resources by your post.
ReplyDeleteDevOps Training in Chennai
DevOps Online Training in Chennai
DevOps Training in Bangalore
DevOps Training in Hyderabad
DevOps Training in Coimbatore
DevOps Training
DevOps Online Training
Very good brief to make concept about angular2 perfect way to accept the updates and this post helped me alot. keep it up!!
ReplyDeleteJava training in Chennai
Java Online training in Chennai
Java Course in Chennai
Best JAVA Training Institutes in Chennai
Java training in Bangalore
Java training in Hyderabad
Java Training in Coimbatore
Java Training
Java Online Training
Thanks for the feedback lavanya :D
DeleteThank you for the information. It is very useful and informative
ReplyDeleteangular js course in chennai
angular course in chennai
angular js online course in chennai
angular js course in bangalore
angular js course in hyderabad
angular js course in coimbatore
angular js course
angular js online course
Thanks for this. I really like what you've posted here and wish you the best of luck with this blog and thanks for sharing.
ReplyDeleteAWS Course in Chennai
AWS Course in Bangalore
AWS Course in Hyderabad
AWS Course in Coimbatore
AWS Course
AWS Certification Course
AWS Certification Training
AWS Online Training
AWS Training
Thank you Radhika :D
DeleteGreat Info! ...Thanks for sharing information with us.
ReplyDeleteacte chennai
acte complaints
acte reviews
acte trainer complaints
acte trainer reviews
acte velachery reviews complaints
acte tambaram reviews complaints
acte anna nagar reviews complaints
acte porur reviews complaints
acte omr reviews complaints
Thank you VIvek! You're welcome!
DeleteYou’re a very skilled blogger.this post help in download & force to think I have joined your feed and look forward to seeking more of your fantastic post. Also, I have shared your web site in my social networks.keep it up!!
ReplyDeletepython training in bangalore
python training in hyderabad
python online training
python training
python flask training
python flask online training
python training in coimbatore
Thank you very much Aishu :D Glad to hear :D
ReplyDeleteThank you!
ReplyDeleteThank you swaroop!
ReplyDeleteA 'soft-skill' according to Wikipedia is: a combination of people skills, social skills, communication skills, character or personality traits, attitudes, career attributes, social intelligence and emotional intelligence quotients, among others, that enable people to navigate their environment, work well with others..thanks!!
ReplyDeleteAndroid Training in Chennai
Android Online Training in Chennai
Android Training in Bangalore
Android Training in Hyderabad
Android Training in Coimbatore
Android Training
Android Online Training
Such a great post.
ReplyDeleteAt this blog you get something interesting and very informative.
Cyber Security Training Course in Chennai | Certification | Cyber Security Online Training Course | Ethical Hacking Training Course in Chennai | Certification | Ethical Hacking Online Training Course | CCNA Training Course in Chennai | Certification | CCNA Online Training Course | RPA Robotic Process Automation Training Course in Chennai | Certification | RPA Training Course Chennai | SEO Training in Chennai | Certification | SEO Online Training Course
Thank you shiva!
DeleteThank you anand!
ReplyDeleteThank you Siva :D
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteI'm excited to get started with React JS and Sweet Alert integration! Sweet Alert provides customized alerts with ease. This tutorial will show you how to smoothly integrate it with React. Need expert Reactjs development services? Visit Infowind website for high-quality services!
ReplyDeleteT10 Exchange offers seamless online gaming and sports exchange experiences. With a user-friendly interface, diverse game options, secure transactions, and 24/7 customer support, it’s the go-to platform for enthusiasts. Explore innovative features and join a trusted community to enhance your gaming journey.
ReplyDeleteSatsport is your ultimate destination for cutting-edge sports insights and services in India. Offering a seamless platform for sports enthusiasts, we specialize in delivering real-time updates, secure transactions, and an unmatched user experience. Discover the best of sports engagement with Satsports today!"
ReplyDelete