emilkowalski / sonner

An opinionated toast component for React.

Home Page:https://sonner.emilkowal.ski

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to get a handle to internal mounted state for checking if it first render or not?

ahmetkca opened this issue · comments

is there a way to get the internal mounted state to check if it is first render or not? From what I understand sonner already renders your custom component ones for triggering css animations.

React.useEffect(() => {
    // Trigger enter animation without using CSS animation
    setMounted(true);
}, []);

https://github.com/emilkowalski/sonner/blob/c449e2741368b04b4524859aa2a60696c0cfb58c/src/index.tsx#L105C26-L105C26

What's your use case?

I had a toast. Promise toast where I show progress of the uploads of the files. I was passing promises and doing some state update whenever a promise is resolved. I was updating the states twice the size of promise list somehow and I thought this was the problem. Fortunately, I resolved by creating my own first render check with useRef.