Core API
destroy()
Permanently garbage collects the engine and DOM nodes.
destroy()
Safely cleans up DOM traces and notifies all plugins. Should be explicitly invoked during framework dismount phases (React useEffect cleanup) to ensure you avoid memory leaks.
Any tasks queued in .then() chains halt permanently.
Use Cases
- React unmounting: Ensuring that the cursor elements generated for a specific route demo are cleaned up when the user navigates away.
- Session stop: Terminating automation once the user explicitly cancels or closes a modal showing the interactive guide.
Example
import { useEffect } from 'react';
import { Cursor } from '@cursor.js/core';
export default function App() {
useEffect(() => {
const cursor = new Cursor()
.hover('#link')
.click('#link');
return () => {
cursor.destroy(); // Safely clean up
};
}, []);
return <nav id="link">Home</nav>;
}