()
| 155 | } |
| 156 | |
| 157 | function useToast() { |
| 158 | const [state, setState] = useState<State>(memoryState) |
| 159 | |
| 160 | useEffect(() => { |
| 161 | listeners.push(setState) |
| 162 | return () => { |
| 163 | const index = listeners.indexOf(setState) |
| 164 | if (index > -1) { |
| 165 | listeners.splice(index, 1) |
| 166 | } |
| 167 | } |
| 168 | }, [state]) |
| 169 | |
| 170 | return { |
| 171 | ...state, |
| 172 | toast, |
| 173 | dismiss: (toastId?: string) => dispatch({ type: "DISMISS_TOAST", toastId }), |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | export { useToast, toast } |
no test coverage detected