-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Closed
Labels
Description
Describe the feature you'd love to see
Similar to the new React 19 feature, it would be great to be able to use cleanup functions with callback refs.
<input
ref={(ref) => {
// ref created
// REQUESTED: return a cleanup function to reset
// the ref when element is removed from DOM.
return () => {
// ref cleanup
};
}}
/>This would make it easier to connect Preact components to DOM APIs like MutationObserver, which currently need some hooks/effects. Using object refs and effects is more error-prone as it requires syncing up whatever conditional rendering logic you have between your returned elements and effects.
Additional context (optional)
https://react.dev/blog/2024/04/25/react-19#cleanup-functions-for-refs