unmount()
Unmounts a previously rendered React tree from a canvas and cleans up all resources.
Signature
function unmount(canvas: HTMLCanvasElement): voidParameters
| Parameter | Type | Description |
|---|---|---|
canvas | HTMLCanvasElement | The canvas to unmount |
Usage
import { render, unmount } from 'react-pxl'
const canvas = document.getElementById('canvas') as HTMLCanvasElement
// Render
render(<App />, canvas)
// Later, clean up
unmount(canvas)Behavior
- Detaches the event dispatcher (removes all canvas and window event listeners)
- Unmounts the React reconciler container
- Clears the canvas
Call unmount() when removing the canvas from the page or when you need to stop rendering. This prevents memory leaks from lingering event listeners and image references.
Last updated on