destroy

destroy()

Cleans up the button and closes any open payment modals.

Syntax

button.destroy()

Returns

  • Type: void

  • Description: No return value

When to Use

Call destroy() when:

  • Component unmounts (React, Vue, Angular)

  • Page navigation occurs

  • Button is removed from the DOM

  • Application cleanup is needed

Usage

React Component Cleanup:

useEffect(() => {
  const button = new ButtonDynamicPrice({
    price: 99.99,
    apiKey: "your_api_key"
  });

  buttonRef.current.appendChild(button.render());

  // Cleanup function
  return () => {
    button.destroy();  // Remove button and close modal
  };
}, []);

Manual Cleanup:

const button = new ButtonDynamicPrice({
  price: 49.99,
  apiKey: "your_api_key"
});

document.getElementById('container').appendChild(button.render());

// Later, when removing the button
button.destroy();

What destroy() Does:

  1. Removes the button element from the DOM

  2. Closes any open payment modals

  3. Cleans up event listeners

  4. Prevents memory leaks

Last updated

Was this helpful?