Skip to content

Conversation

@dutchcelt
Copy link

The goal is to allow users to create wrappers with a specific behavior for useRef by toggling the application of 'useImperativeHandle'.

This PR does three things:

  1. Adds the config option withImperativeHandle
  2. Using the option to omit the useImperativeHandle feature so that users can retrieve the custom element from ref.current.
  3. The useImperativeHandle when used, now gets a 'customElement' property as a fallback to retrieve the custom element.

@break-stuff
Copy link
Owner

I think this can be simplified. By updating the ref prop on the custom element like this:

      ref: (node) => {
        ref.current = node; // Assign the DOM node to the internal ref
        if (typeof forwardedRef === "function") {
          forwardedRef(node); // Support callback refs
        } else if (forwardedRef) {
          forwardedRef.current = node; // Support object refs
        }
      },

That should resolve the ref mapping issue and we should be able to remove the useImperativeHandle function completly.

@dutchcelt
Copy link
Author

I can update the commit removing the useImperativeHandle and related methods and using the simplified ref function. Unless you'd rather do that?

@break-stuff
Copy link
Owner

Please, go ahead. You've done most of the leg work already. 😄

…implementation and reduced the solution to a simple `ref` update function.
@break-stuff break-stuff merged commit 3d33589 into break-stuff:main May 8, 2025
1 check passed
@break-stuff
Copy link
Owner

@dutchcelt The fix has been deployed under v1.7.1. I appreciate your help on this!

@dutchcelt dutchcelt deleted the feature/toggle-the-use-of-useImperativeHandle branch May 8, 2025 18:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants