Skip to content

How to extend and add props to a Theme UI component (with TypeScript) #1895

Answered by jfriestedt
mrmartineau asked this question in Q&A
Discussion options

You must be logged in to vote

@mrmartineau

In order for your component to continue to support ref forwarding like the Theme UI button does, while still having your component be functional as opposed to class based, you'll have to actually call the React.forwardRef() function (see https://reactjs.org/docs/forwarding-refs.html)

As far as your props interface goes, the component itself should be typed as a ForwardRef instance, not the props signature. The props themselves can just extend the aliased ThemeUIButtonProps.

You also shouldn't need to explicitly add sx or children to your interface if you're extending ThemeUIButtonProps

Putting all that together it should look something like

export interface ButtonProps extends 

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mrmartineau
Comment options

@mrmartineau
Comment options

Answer selected by mrmartineau
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants