Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Showing a custom toast function for react-toastify - Toast show

import { toast } from "react-toastify";
const defaultPosition = toast.POSITION.BOTTOM_CENTER;

/**
 * Show Toast
 *
 * Display toast
 *
 * @param {string} type message type, success/error
 * @param {string} msg toast message
 * @param {integer} autoClose auto close value in millisecond
 * @param {string} className toaster class name
 * @param {string} position toast position; ex-'top-right', 'top-center', 'top-left', 'bottom-right', 'bottom-center', 'bottom-left'
 */

export const showToast = ( type = "success", msg, autoClose = 2000, className = "primaryColor", position = defaultPosition ) => {
  if (type === "success") {
    toast.success(msg, {
      autoClose: autoClose === null ? 2000 : autoClose,
      className: className === null ? "primaryColor" : className,
      position: position,
    });
  } else if (type === "error") {
    toast.error(msg, {
      autoClose: autoClose === null ? 2000 : autoClose,
      className: className === null ? "dangerColor" : className,
      position: position,
    });
  }
};


// How to use react-toastify
showToast('success', 'Product add to cart successfully !');

showToast('error', 'Please fill the inputs properly.');
Comment

PREVIOUS NEXT
Code Example
Javascript :: react native position 
Javascript :: function js 
Javascript :: javscript call 
Javascript :: javascript add field to array 
Javascript :: initialize firebase app 
Javascript :: sequelize transaction 
Javascript :: how to create new route in express 
Javascript :: jquery get return jquery object 
Javascript :: click tester 
Javascript :: wild card select jquery 
Javascript :: recordrtc 
Javascript :: this in ajax call 
Javascript :: how to delete an exact element of array 
Javascript :: Serve the angular application 
Javascript :: hide component vuejs 
Javascript :: js console log 
Javascript :: javascript this Inside Object Method 
Javascript :: $(...).DataTable is not a function 
Javascript :: Difference between “ == “ and “ === “ operators. 
Javascript :: map function in js 
Javascript :: rxjs takeuntil 
Javascript :: $(...).Datatables is not a function 
Javascript :: vue js documentation 
Javascript :: Find items from object 
Javascript :: email validation in javascript 
Javascript :: class 
Javascript :: typeorm in 
Javascript :: inner function in javascript 
Javascript :: javascript map method 
Javascript :: Updating a nested object in a document using mongoose 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =