We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent f98e464 commit a5b9e77Copy full SHA for a5b9e77
src/hooks/use-toast.ts
@@ -171,6 +171,9 @@ function toast({ ...props }: Toast) {
171
function useToast() {
172
const [state, setState] = React.useState<State>(memoryState)
173
174
+ // Subscribe to toast state updates once on mount. Using an empty
175
+ // dependency array prevents repeatedly adding the same listener
176
+ // whenever state changes, which previously caused a memory leak.
177
React.useEffect(() => {
178
listeners.push(setState)
179
return () => {
@@ -179,7 +182,7 @@ function useToast() {
182
listeners.splice(index, 1)
180
183
}
181
184
- }, [state])
185
+ }, [])
186
187
return {
188
...state,
0 commit comments