Skip to content

Commit 531d1e7

Browse files
committed
refactor: allow using overlay hook without the context
1 parent 4fb2abb commit 531d1e7

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

.changeset/shaggy-apples-travel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'dragswag': minor
3+
---
4+
5+
BREAKING: Overlay is moved to a context, DragOverlayProvider

packages/dragswag/src/react/drag-overlay.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,17 @@ export function DragOverlayProvider({ children, ...rest }: DragOverlayProviderPr
6363
)
6464
}
6565

66-
export function useDragOverlayElement() {
66+
const noContext: DragOverlayContextType = {
67+
dragElement: null,
68+
setDragElement: () => {},
69+
setDragElementPosition: () => {},
70+
}
71+
72+
export function useDragOverlayElement(): DragOverlayContextType {
6773
const context = useContext(DragOverlayContext)
6874
if (!context) {
69-
throw new Error('useDragOverlayElement must be used within a DragOverlayProvider')
75+
console.warn('useDragOverlayElement must be used within a DragOverlayProvider')
76+
return noContext
7077
}
7178
return context
7279
}

0 commit comments

Comments
 (0)