Skip to content

Commit

Permalink
fix(useSortable): prevent from creating multi instances (#3501)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doctor-wu committed Nov 9, 2023
1 parent e024235 commit d98468d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/integrations/useSortable/index.ts
Expand Up @@ -39,7 +39,7 @@ export function useSortable<T>(
list: MaybeRefOrGetter<T[]>,
options: UseSortableOptions = {},
): UseSortableReturn {
let sortable: Sortable
let sortable: Sortable | undefined

const { document = defaultDocument, ...resetOptions } = options

Expand All @@ -51,12 +51,15 @@ export function useSortable<T>(

const start = () => {
const target = (typeof el === 'string' ? document?.querySelector(el) : unrefElement(el))
if (!target)
if (!target || sortable !== undefined)
return
sortable = new Sortable(target as HTMLElement, { ...defaultOptions, ...resetOptions })
}

const stop = () => sortable?.destroy()
const stop = () => {
sortable?.destroy()
sortable = undefined
}

const option = <K extends keyof Options>(name: K, value?: Options[K]) => {
if (value !== undefined)
Expand Down

0 comments on commit d98468d

Please sign in to comment.