Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot set properties of undefined (setting 'toggle') #1150

Open
NwosaEmeka opened this issue Aug 28, 2024 · 8 comments
Open

Cannot set properties of undefined (setting 'toggle') #1150

NwosaEmeka opened this issue Aug 28, 2024 · 8 comments

Comments

@NwosaEmeka
Copy link

NwosaEmeka commented Aug 28, 2024

bug

What is the current behavior?
I recently upgraded to React 18 and react-toastify 10.0.5, since then, I keep getting this error Cannot set properties of undefined (setting 'toggle') any pointers on how to resolve this? attached is screenshot of the issue

image

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React: 18.2.0
react-toastify: "^10.0.5"

browswer: Safari 17.4.1

@github-staff github-staff deleted a comment Aug 28, 2024
@m-nathani
Copy link

We are facing the issue as well... would be nice if there is some insights on this.. and possible way to fix it please 🙏🏼

@pradeepgudipati
Copy link

pradeepgudipati commented Sep 4, 2024

I get the same error now randomnly !

And here is the console log for the -- error

redirect-boundary.js:57 Uncaught TypeError: Cannot set properties of undefined (setting 'toggle')
at Object.setToggle (page.js:3109:45)
at N (page.js:3179:32)
at R (page.js:3401:101)
at renderWithHooks (react-dom.development.js:11121:18)
at updateFunctionComponent (react-dom.development.js:16290:20)
at beginWork$1 (react-dom.development.js:18472:16)
at beginWork (react-dom.development.js:26927:14)
at performUnitOfWork (react-dom.development.js:25748:12)
at workLoopSync (react-dom.development.js:25464:5)
at renderRootSync (react-dom.development.js:25419:7)
at recoverFromConcurrentError (react-dom.development.js:24597:20)
at performSyncWorkOnRoot (react-dom.development.js:24899:20)
at flushSyncWorkAcrossRoots_impl (react-dom.development.js:7758:13)
at flushSyncWorkOnAllRoots (react-dom.development.js:7718:3)
at processRootScheduleInMicrotask (react-dom.development.js:7863:3)
at eval (react-dom.development.js:8034:7)

@pradeepgudipati
Copy link

pradeepgudipati commented Sep 4, 2024

my specific sample code is below

page.tsx code

const notifyNoActivity = () => toast.info("Sample Message here ", {
         position: "top-right",
         autoClose: 5000,
         hideProgressBar: false,
         closeOnClick: true,
         pauseOnHover: true,
         draggable: true,
         progress: undefined,
         theme: "light",
         transition: Bounce,
     });
     
       useEffect(() => {
        if (showTimeOutMessage) {
            notifyNoActivity();
        }
    }, [showTimeOutMessage]);

     const pushTimeoutMessage = () => {
         setShowTimeOutMessage(true);
     };
 
     const {start, stop, reset, isActive} = useTimer(pushTimeoutMessage, 5);

useTimer.ts file

import {useEffect, useRef, useState} from "react";
 
 const useTimer = (callback: () => void, delayInSeconds: number) => {
     const [isActive, setIsActive] = useState(false);
     const timerId = useRef<NodeJS.Timeout | null>(null);
 
     useEffect(() => {
         if (isActive) {
             timerId.current = setTimeout(() => {
                 callback();
                 setIsActive(prev => false);
             }, delayInSeconds * 1000);
         }
 
         return () => {
             if (timerId.current) {
                 clearTimeout(timerId.current);
             }
         };
     }, [isActive, delayInSeconds, callback]);
 
     const start = () => {
         setIsActive(prev => true);
     };
 
     const stop = () => {
         if (timerId.current) {
             clearTimeout(timerId.current);
         }
         setIsActive(prev => false);
     };
 
     const reset = () => {
         stop();
         start();
     };
 
     return {start, stop, reset, isActive};
 };
 
 export default useTimer;

@amila-t-kumarasekara
Copy link

amila-t-kumarasekara commented Sep 4, 2024

**pradeepgudipati ** commented Sep 4, 2024

What is the purpose of doing this progress: undefined ?

@pradeepgudipati
Copy link

@amila-t-kumarasekara

I have taken the sample code from the demo site and there it is undefined !

https://fkhadra.github.io/react-toastify/introduction/

@savanfami
Copy link

i have also faced this issue any suggestions...???

@pradeepgudipati
Copy link

@amila-t-kumarasekara would be great if you could also try and then get back with a suggestion instead of just replying here. BTW the removal of progress doesn't really make any difference! it still crashes !

@Hassan1ahmad
Copy link

i am also getting the same error. any suggestions...?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants