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.
Linkhttps://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:


Error message:


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!




48 Comments

  1. Nice Blog!
    I'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.

    ReplyDelete
  2. Very Nice Blog ...
    I have gone through all your sweet alerts .These sweet alerts will help the reactjs web development company. Thank you for sharing this article.

    ReplyDelete
    Replies
    1. Thank you for your feedback :D Keep in touvh with TechPool!

      Delete
    2. I 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 .

      Delete
  3. Great 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.
    Taxi Dispatch App | Taxi Service Providers | Safety and Health Management System

    ReplyDelete
  4. Thank you very much Ajish! Will do more...

    ReplyDelete
  5. Good 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

    ReplyDelete
  6. Greetings! Very helpful advice within this article! It is the little changes that produce the largest changes. Many thanks for sharing!
    Reactjs Training in Bagalore

    ReplyDelete
  7. Being 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!

    Read More: Best React JS Development Companies in India

    ReplyDelete
  8. 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.

    ReplyDelete
  9. 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. Reactjs Tutorials Online

    ReplyDelete
  10. This 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.
    DevOps 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

    ReplyDelete
  11. You’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!!

    python training in bangalore

    python training in hyderabad

    python online training

    python training

    python flask training

    python flask online training

    python training in coimbatore


    ReplyDelete
  12. Thank you very much Aishu :D Glad to hear :D

    ReplyDelete
  13. A '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!!

    Android 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

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. I'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!

    ReplyDelete