Issue with React-Toastify not displaying on the screen

After updating from React-Toastify version 7.0.3 to 9.0.3, I encountered an issue where notifications are not rendering at all.

Here are the steps I followed:

  1. yarn add [email protected]
  2. Modified Notification file
import React from "react";
import { ToastContainer, toast } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
const ReactToastify = require("react-toastify");
/**
 * 
 * @param {severity, title, message} params 
 */
export const toastnotify = (params) => {
    switch (params.severity) {
        case "success":
            toast.success(params.message,
                {
                    position: "top-right",
                    autoClose: 3000,
                    hideProgressBar: false,
                    closeOnClick: true,
                    pauseOnHover: true,
                    draggable: true,
                    progress: undefined,
                    theme: "light",
                });
            break;
        case "critical":
            toast.error(params.message, {
                position: "top-right",
                autoClose: 3000,
                hideProgressBar: false,
                closeOnClick: true,
                pauseOnHover: true,
                draggable: true,
                progress: undefined,
                theme: "light",
            });
            break;
        case "warning":
            toast.warn(params.message, {
                position: "top-right",
                autoClose: 3000,
                hideProgressBar: false,
                closeOnClick: true,
                pauseOnHover: true,
                draggable: true,
                progress: undefined,
                theme: "light",
            });
            break;
        default: toast(params.message);
            break;
    }
};
export const ToastNotificationsContainer = (props) => {
    return (
        <ToastContainer
            position="top-right"
            autoClose={3000}
            hideProgressBar={false}
            newestOnTop={false}
            closeOnClick
            rtl={false}
            pauseOnFocusLoss
            draggable
            pauseOnHover
            theme="light" />);
};
export const NotificationContainer = (props) => {
    return (<ReactToastify.ToastContainer
        hideProgressBar={true}
        autoClose={3000}
        closeOnClick={true}
        closeButton={false}
        newestOnTop={true}
        position="top-right"
        toastClassName="toast-notification-wrap" />);
};
  1. In App.js,
import { NotificationContainer } from "./shared/Notifications/notifications";
render() {
    return (
      <Fragment>
        <AppHeader />
        <NotificationContainer/>
        <AppSidebar>
        </AppSidebar>
        <AppFooter />
      </Fragment>
    );
  }
  1. When attempting to use the notification,
import { toastnotify } from "../../shared/Notifications/notifications";

//Inside function
toastnotify({ severity: "critical", title: "Unable to fetch log details" })

I have carefully followed the documentation but cannot pinpoint what went wrong. The main difference between the code bases is in the notification.js files of versions 7.0.3 and 9.0.3.

import { Notification } from '@scuf/common';
import './notifications.scss';
import 'react-toastify/dist/ReactToastify.css';

const ReactToastify =  require('react-toastify');
/**
 * 
 * @param {severity, title, message} params 
 */
export const toastnotify = (params) => {
    ReactToastify.toast(
        <Notification
            hasIcon={true}
            className="toast-notification"
            severity={params.severity}
            title={params.title}
        >
            {params.message || ""}
        </Notification>
    )
}

export const NotificationContainer = (props) => {
    return(
        <ReactToastify.ToastContainer
            hideProgressBar={true}
            autoClose={12000}
            closeOnClick={true}
            closeButton={false}
            newestOnTop={true}
            position="bottom-right"
            toastClassName="toast-notification-wrap"
        />
    )
}

If you notice any missing steps or incorrect modifications, please let me know.

Answer №1

If you encounter the same issue, check out the "Issues" section of the React-Toastify repository. There is a user who found a solution by using version 9.1.2.

For more information, visit this link.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Peer dependency not met in NPM package

My current project is utilizing <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="8ad8efebe9fecabbbfa4bea4bb">[email protected]</a>. Now I am looking to integrate this package, but encountering the following error: ...

Observing the data retrieved from an AJAX request

Currently, I have this AJAX call in my code: $('#search').keyup(function() { $.ajax({ type: "GET", url: "/main/search/", data: { 'search_text': $('#search').val() }, suc ...

Personalizing the text of an item in a v-select interface

Can the item-text be customized for the v-select component? I am interested in customizing each item within the v-select dropdown, similar to this example: :item-text="item.name - item.description" ...

How to handle form-data in NestJS Guards?

I've been trying to access form-data in my NestJS Guards, but I'm experiencing some difficulties. Despite following the tutorial provided here, I am unable to see the request body for my form-data input within the Guard itself. However, once I ac ...

Navigating with Next.js router.push() changes the URL but fails to actually display the page

My Next.js app is running on localhost:3000 and it redirects to a login page if there is no user data. However, when it redirects to the login page, it doesn't render and I encounter this error: Error: Objects are not valid as a React child (found: [o ...

Is there a way to make sure that the antd datepicker response is sent to the backend only after I click on the submit button?

After receiving a response from the antd datepicker and successfully sending it to the backend, I encountered an issue. The response is automatically sent to the backend as soon as a date is selected. However, I want the request to be sent only after click ...

Deployment of a NextJS14 app to Vercel encountered an issue: Unexpected token '<' found in JSON at position 0

Here is the issue at hand: next: 14.1.4 next-auth: 4.24.7 node version: 20 This is the structure of my authentication folder: No errors occur when running npm run dev I've been investigating this issue for three days, but I am still stuck. I belie ...

What is the best way to save a 2D array to cookies?

I am attempting to save states into cookies using the react-cookie package. Storing strings in the cookie is working fine for me, but I am facing an issue when trying to store arrays. Let's say I have an array structured like this: const arr = [ ...

My function doesn't seem to be cooperating with async/await

const initialState={ isLoggedIn: false, userData: null, } function App() { const [state, setState]= useState(initialState) useEffect(()=>{ async function fetchUserData(){ await initializeUserInfo({state, setState}) // encountering an ...

Learn the technique of coding HTML within inline JavaScript, along with implementing CSS inline styling

I'm looking for a way to incorporate HTML within inline JavaScript, along with CSS inline styles. Can someone provide guidance on how to achieve this? For example, something like the following code snippet: <p><span style="color: #00ff00;"&g ...

A guide on identifying the data type of a value entered into an HTML table using JavaScript

Currently, I am tackling a contenteditable HTML table challenge. My goal is to enforce the insertion of only numeric values while alerting the user if they attempt to input strings or non-numeric characters. Can anyone provide guidance on how to achieve th ...

Looking to update the date in 'React Fullcalendar' using a 'drop-down' filter. How can this be accomplished?

Is there a way to change the viewing date of a component using a 'DropDown' filter? I've seen plenty of answers about changing views, but nothing specifically on changing dates T^T Can anyone provide some helpful insights on this topic? ...

Ensure that the central section of the slider remains illuminated

Looking for help with customizing my "product" slider, lightSlider. I want the middle div to always be highlighted when navigating through the slider. Here's what it looks like currently: Link to screenshot - current. My goal is to achieve this look: ...

Preserve the checkbox state upon refreshing the page

I am facing an issue with keeping the checkbox state saved after a page reload. Currently, I have stored my unchecked checkboxes in localStorage, but I am unsure about what steps to take next. In simple terms, I want the checkbox to remain unchecked when I ...

An issue encountered with getServerSideProps in NextJS 12 is causing a HttpError stating that cookies are not iterable, leading

Currently, I have an application running smoothly on my localhost. However, when it comes to production, an unexpected error has popped up: Error: HttpError: cookies is not iterable at handleError (/usr/src/.next/server/chunks/6830.js:163:11) at sendReques ...

Ensuring that a Box retains its visual appeal even as the screen size fluctuates within MaterialUI in ReactJS

Struggling with a minor yet bothersome issue related to an Avatar within my MaterialUI sidebar. Trying to maintain the proportion of this wrapped Avatar image(Link: https://i.stack.imgur.com/lt1Lj.png) as the screen size changes, but it slowly disappears ...

Exploring methods to conduct testing on an AngularJS application using AngularJS end-to-end testing, specifically focusing on scenarios involving multiple inputs

Our program includes a directive that is repeated multiple times with an input field. The structure of our code resembles the following: <li> <label>AMI</label> <div class="searchbox" searchbox="" filter="search.ami"> ...

Submit a collection of images and an object to the server using ReactJS

I'm currently working with Reactjs on the frontend. In order to set the profile picture to state, I've implemented the following code: handleImageChange = (event) => { event.preventDefault(); var file = event.target.files[ ...

Data loss from AngularJS multipartForm directive when redirecting to different routes

Having trouble with an Excel file uploader and data parsing in the routes? It seems like the FormData is getting lost when sent through the $http service route. Any advice or experience on how to handle this issue would be greatly appreciated! Html View: ...

I prefer not to run the next.js SWR until after the initial rendering

Development Setup ・ next.js ・ typescript ・ swr This uses swr for communication purposes. I am looking to only trigger it when the query value changes. However, it is also being executed during the initial rendering. How can I prevent it ...