Skip to content

Add example with type-safe destructuring #3325

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mindplay-dk
Copy link

What:

This adds an example of extending and styling an intrinsic element with type-safety.

Why:

The examples in the docs only show how to style intrinsic elements with no callback for the actual tag - this is clearly something React devs struggle with in TypeScript, and it's made more difficult by also needing the styled call.

I spent almost a day before landing on a reasonably simple and satisfying approach, so I figured this can help others. :-)

I honestly feel like you should promote this pattern as the first-and-foremost option. Many of the other options will simply have you run into a wall, having to refactor to this pattern anyway. For example, styled.div doesn't give you any real control of anything - you'll need a custom prop, which you will then learn how to filter out using shouldForwardProp. Then you'll need a custom attribute, or you'll need a default value for a prop, really anything besides just forwarding, and you will need this pattern anyway. To be honest, I don't think all these "shortcuts" or "workarounds" should even exist, or at least I don't think they should be promoted - they are incomplete abstractions, so when things change, you'll need to refactor anyway. Just show me one approach first that always works - leave those shorthand options a secondary choices for people who insist on brevity over ease of change.

Just my opinion! so I'm going to leave that for your consideration. :-)

Copy link

changeset-bot bot commented Apr 3, 2025

⚠️ No Changeset found

Latest commit: 1824055

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link

codesandbox-ci bot commented Apr 3, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

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.

1 participant