-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
74 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Clean-up (`destroy`) | ||
|
||
To ensure proper clean-up you should use the `destroy` method returned by `draggy()`. | ||
This will help avoid memory leaks and other potential issues. | ||
|
||
```ts | ||
import { draggy } from "@sebkolind/draggy"; | ||
|
||
const { destroy } = draggy({ target: ".container" }); | ||
|
||
// Call when `draggy` is no longer needed | ||
destroy(); | ||
``` | ||
|
||
## Vue | ||
|
||
When using Vue you can manage the initialization and destruction of the Draggy instance using Vue's lifecycle hooks. | ||
|
||
```vue | ||
<template> | ||
<div class="container"> | ||
<div>Draggable</div> | ||
<div>Draggable</div> | ||
<div>Draggable</div> | ||
</div> | ||
</template> | ||
<script setup> | ||
import { draggy } from "@sebkolind/draggy"; | ||
let instance; | ||
onMounted(() => { | ||
instance = draggy({ target: ".container" }); | ||
}); | ||
onUnmounted(() => { | ||
instance?.destroy(); | ||
}); | ||
</script> | ||
``` | ||
|
||
## React | ||
|
||
If used with React you can use the `useEffect` hook to handle the | ||
initialization and clean-up of the Draggy instance. | ||
|
||
```tsx | ||
import { useEffect } from "react"; | ||
import { draggy } from "@sebkolind/draggy"; | ||
|
||
const DraggableComponent = () => { | ||
useEffect(() => { | ||
const { destroy } = draggy({ target: ".container" }); | ||
|
||
// Clean up on component unmount | ||
return () => { | ||
destroy(); | ||
}; | ||
}, []); | ||
|
||
return ( | ||
<div className="container"> | ||
<div>Draggable</div> | ||
<div>Draggable</div> | ||
<div>Draggable</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export { DraggableComponent }; | ||
``` |