Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[useRenderer] Add public hook #1418

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

Conversation

mnajdova
Copy link
Member

@mnajdova mnajdova commented Feb 5, 2025

Added a public useRenderer hook as an simpler adapter that uses the useComponentRenderer hook. Let me know if this is what we want, and if we agree I will add a documentation for it.

I intentionally copied the types, so we make sure we don't break them if we ever change the internal useComponentRenderer hook. I removed only the customStyleHookMapping setting from the original hook.

Example usage: https://codesandbox.io/p/sandbox/exciting-paper-9x266p-use-renderer-forked-ry269y?file=%2Fpackage.json (thanks Albert for creating it :))

Copy link

netlify bot commented Feb 5, 2025

Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 1b705fa
🔍 Latest deploy log https://app.netlify.com/sites/base-ui/deploys/67a3683e5a353a0008314672
😎 Deploy Preview https://deploy-preview-1418--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mj12albert mj12albert linked an issue Feb 5, 2025 that may be closed by this pull request
@mnajdova mnajdova marked this pull request as draft February 5, 2025 11:56
@mnajdova mnajdova added the new feature New feature or request label Feb 5, 2025
Copy link
Member

@mj12albert mj12albert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice ~ I imagine the use-case is something like this: https://codesandbox.io/p/sandbox/flamboyant-fog-9x266p?file=%2Fsrc%2FApp.tsx%3A29%2C63
(for some reason importing the hook in CSB doesn't work, this works fine locally in a playground though)

This feels more intuitive to me (biased though because I never used asChild extensively) to use than a Slot component

@mnajdova
Copy link
Member Author

mnajdova commented Feb 5, 2025

for some reason importing the hook in CSB doesn't work, this works fine locally in a playground though

I haven't updated the exports field, will fix it. Here is the updated sandbox: https://codesandbox.io/p/sandbox/exciting-paper-9x266p-use-renderer-forked-ry269y?file=%2Fpackage.json

* A function that returns props for the rendered element.
* It should accept and merge additional props.
*/
propGetter?: (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO propGetter is pretty specific to our setup, where we have hooks with logic and components using them.

@mj12albert
Copy link
Member

I removed only the customStyleHookMapping setting from the original hook

It may be useful to provide a (alternative) way to opt-out individual props placed in state from generating a corresponding data attribute

Comment on lines +44 to +47
/**
* Additional props to be spread on the rendered element.
*/
extraProps?: Record<string, any>;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could possibly just be the top-level object props (along with removing propGetter)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[core] Could useComponentRenderer be exported as a util?
4 participants