({ ...props }: Toast)
| 138 | type Toast = Omit<ToasterToast, 'id'>; |
| 139 | |
| 140 | function toast({ ...props }: Toast) { |
| 141 | const id = genId(); |
| 142 | |
| 143 | const update = (props: ToasterToast) => |
| 144 | dispatch({ |
| 145 | type: 'UPDATE_TOAST', |
| 146 | toast: { |
| 147 | duration: TOAST_DURATION, |
| 148 | ...props, |
| 149 | id, |
| 150 | }, |
| 151 | }); |
| 152 | const dismiss = () => dispatch({ type: 'DISMISS_TOAST', toastId: id }); |
| 153 | |
| 154 | dispatch({ |
| 155 | type: 'ADD_TOAST', |
| 156 | toast: { |
| 157 | duration: TOAST_DURATION, |
| 158 | ...props, |
| 159 | id, |
| 160 | open: true, |
| 161 | onOpenChange: (open) => { |
| 162 | if (!open) dismiss(); |
| 163 | }, |
| 164 | }, |
| 165 | }); |
| 166 | |
| 167 | return { |
| 168 | id: id, |
| 169 | dismiss, |
| 170 | update, |
| 171 | }; |
| 172 | } |
| 173 | |
| 174 | function useToast() { |
| 175 | const [state, setState] = React.useState<State>(memoryState); |
no test coverage detected
searching dependent graphs…