sx prop on custom components not working
See original GitHub issueI’ve noticed while writing components that the sx prop didn’t work on custom components which i’d built myself, but when i went to use it with other plugin libraries (fontawesome for example) it did work as expected. So am i missing something? I can’t imagine large libraries like FA are doing something special to accept the sx prop.
An example component i’ve made (though this seems to affect everything i’ve written, so i’m curious what’s wrong).
/** @jsx jsx */
import { jsx } from 'theme-ui'
interface PropTypes {
to: string
variant?: string
children: string
}
const Button = ({ to, variant, children }: PropTypes) => (
<a
href={to}
className={`button`}
sx={{
px: 3,
py: 2,
border: 0,
borderRadius: 4,
cursor: 'pointer',
variant: variant ? `buttons.${variant}` : `buttons.primary`,
}}
>
{children}
</a>
)
export default Button
<Button to='#' variantbutton='primary'>Button text</Button>
What i’d like to do, as an example
<Button to='#' variantbutton='primary' sx={{ display: 'flex' }}>Button text</Button>
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
sx prop not getting transformed in custom components ...
Check your component code, you might import the v4 component: import ListItemText from "@material-ui/core/ListItemText";.
Read more >sx prop not getting transformed in custom components in ...
[Solved]-sx prop not getting transformed in custom components in Material-UI 5-Reactjs ... In v5, you can use sx directly from the components since...
Read more >The sx prop - MUI System
The sx prop is a shortcut for defining custom styles that has access to the theme. The sx prop lets you work with...
Read more >The `sx` Prop
The sx Prop. The sx prop lets you style elements inline, using values from your theme. To use the sx prop, add the...
Read more >How to use the sx prop in MUI v5. Still using makeStyles?
The form with no custom styling. The page without styling outside of the MUI default components looks a little wonky. The default Typography,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You’ll need to pass the
className
prop through to the underlying HTML element. Thesx
prop is converted toclassName
with Theme UI’sjsx
functionOkay i think i’ve got a solution which is clean & gives no errors.
Best solution so far
No duplicated props, and everything is used some way or another.
Going to close as i’m happy with this solution (especially as sx errors on html elements anyway in ts so removing the errors in my own components is 👌)
Thanks all!