You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is there a recommended way to track when a toast created with useToast().toast() is dismissed (either manually by the user or automatically after the duration)?
Right now, the toast() method doesn’t seem to support an onDismiss callback or reliably trigger onOpenChange
Example
const{ toast, dismiss }=useToast()toast({title: "Save changes?",description: "Do you want to save changes?",duration: 10000,// This doesn't seem to get calledonOpenChange: (open)=>{if(!open){console.log("Toast dismissed")}},})
Original code
constcreateRoofLayer=(roofSurface: RoofSurface,allRoofSurfaces: RoofSurface[]): Feature=>{constcoordinates=[roofSurface.coords]if(roofSurface.superStructures){coordinates.push(...roofSurface.superStructures)}constfeature: Feature={id: `roof-${address}-${roofSurface.id}`,type: "Feature",properties: {id: roofSurface.id,user_roofStatus: "#16a34a",},geometry: {type: "Polygon",coordinates: coordinates,},}// const outlineSourceId = `roof-outline-${address}-${roofSurface.id}`// if (!mapRef.current?.getSource(outlineSourceId)) {// mapRef.current?.addSource(outlineSourceId, {// type: "geojson",// data: feature,// })// // Green fill layer on top with a slight offset// mapRef.current?.addLayer({// id: `${outlineSourceId}-fill`,// type: "fill",// source: outlineSourceId,// paint: {// "fill-color": "#16a34a",// "fill-opacity": 0.2,// "fill-outline-color": "#16a34a",// },// })// // Add visible outline// mapRef.current?.addLayer({// id: outlineSourceId,// type: "line",// source: outlineSourceId,// paint: {// "line-color": "#16a34a",// "line-width": 2,// "line-opacity": 1,// },// })// // Ensure roof layers are always rendered behind panel layers// if (mapRef.current?.getStyle()?.layers) {// // Get the first panel-related layer// const firstPanelLayer = mapRef.current.getStyle()?.layers.find((layer) => layer.id.startsWith("panels"))// if (firstPanelLayer) {// mapRef.current.moveLayer(outlineSourceId, firstPanelLayer.id)// mapRef.current.moveLayer(`${outlineSourceId}-fill`, firstPanelLayer.id)// }// }// }constcurrent=mapRef.currentasMapWithDrawcurrent.draw.add(featureasFeature)// Update the draw.update event to show a toastcurrent.on("draw.update",(e: {features: Feature[]})=>{if(e.features.length>0){constupdatedFeature=e.features[0]// Find the original roof id from the feature idconstfeatureId=updatedFeature.idasstringconstroofIdMatch=featureId.match(/roof-.*-(\d+)/)constroofId=roofIdMatch ? parseInt(roofIdMatch[1]) : nulltoast({className: "flex flex-col justify-start gap-4 items-start relative",title: "Änderungen speichern?",description: "Möchten Sie die Änderungen an diesem Dach speichern?",duration: 10000,// 10 secondsonOpenChange: (open)=>{// This did not work ! if(!open){console.log("Toast was dismissed!")handleCancelRoofChanges(updatedFeature.idasstring,roofId,allRoofSurfaces)}},action: (<divclassName='flex gap-2'><ToastActionclassName='bg-blue-600 hover:bg-blue-700 text-white'altText='Speichern'onClick={()=>{handleSaveRoofChanges(updatedFeature,roofId)}}>
Speichern
</ToastAction><ToastActionaltText='Abbrechen'onClick={()=>{handleCancelRoofChanges(updatedFeature.idasstring,roofId,allRoofSurfaces)}}>
Abbrechen
</ToastAction></div>),})}})returnfeature}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Is there a recommended way to track when a toast created with useToast().toast() is dismissed (either manually by the user or automatically after the duration)?
Right now, the
toast()
method doesn’t seem to support anonDismiss
callback or reliably triggeronOpenChange
Example
Original code
Is there a built-in way to handle this?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions