Removed the useEffect which will be triggered based on the removeId state which will further call the removeToast and invoked the removeToast directly inside the setTimeout.
Code improvements
- if (!toastList) return null;
- if (toastList && !toastList.length) return null;
+ if (!toastList?.length) return null;
will return null for both falsy values(null,undefined) and empty array [ ]
setTimeout
in useEffect.removeId
state which will further call theremoveToast
and invoked theremoveToast
directly inside the setTimeout.will return
null
for both falsy values(null,undefined) and empty array [ ]