Skip to content

Commit

Permalink
fix: simplify useDragType (#3127)
Browse files Browse the repository at this point in the history
* fix: simplify useDragType

* chore: cut semver

* fix: test update
  • Loading branch information
darthtrevino committed Mar 9, 2021
1 parent 769efee commit af1fafa
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
8 changes: 8 additions & 0 deletions .yarn/versions/e6267e85.yml
@@ -0,0 +1,8 @@
releases:
react-dnd: patch

declined:
- react-dnd-documentation
- react-dnd-examples-decorators
- react-dnd-examples-hooks
- react-dnd-test-utils
4 changes: 1 addition & 3 deletions packages/react-dnd/src/hooks/__tests__/useDrag.spec.tsx
Expand Up @@ -34,9 +34,7 @@ describe('The useDrag hook', () => {
try {
const errorMock = jest.fn()
console.error = errorMock
expect(() => render(<Wrapped />)).toThrow(
/spec.type or spec.item.type must be defined/,
)
expect(() => render(<Wrapped />)).toThrow(/spec.type must be defined/)
} finally {
console.error = err
}
Expand Down
5 changes: 2 additions & 3 deletions packages/react-dnd/src/hooks/useDrag/useDragType.ts
Expand Up @@ -7,9 +7,8 @@ export function useDragType(
spec: DragSourceHookSpec<any, any, any>,
): Identifier {
return useMemo(() => {
const result: Identifier | null =
spec.type ?? (spec.item?.type as Identifier) ?? null
invariant(result != null, 'spec.type or spec.item.type must be defined')
const result: Identifier = spec.type
invariant(result != null, 'spec.type must be defined')
return result
}, [spec])
}

0 comments on commit af1fafa

Please sign in to comment.