[Question] How to implement custom component aware of `sx`?
See original GitHub issueHi, I’d like to write a custom component based on theme-ui elements with a structure where children are aware of sx
prop of the parent.
Let say:
export const FooComponent = forwardRef(
(
{ sx: sxParent, ...rest },
ref,
) => {
console.log(sxParent, rest)
return (
<Box {...rest} ref={ref}>
<Text sx={{ backgroundColor: sxParent.backgroundColor || 'black' }}>
foo
</Text>
</Box>
)
},
)
I noticed that if in the file where I call FooComponent
the jsx pragma is present then sxParent
is converted to a { className: 'css-wo3z44' }
, otherwise it is the original object (let say a valid SxStyleProp
object).
How can I handle this? Should I need to parse the css-wo3z44
somehow?
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Adding sx prop to custom component - Stack Overflow
You can use the styled function to add the sx prop to your custom component like this: import { styled } from "@mui/material/styles"; ......
Read more >How To Create Custom Components in React - DigitalOcean
In this tutorial, you'll learn to create custom components in React. Components are independent pieces of functionality that you can reuse ...
Read more >Frequently Asked Questions (WEEE) - European Commission
The purpose of this Frequently Asked Questions (FAQ) document is to clarify certain aspects of ... Do components fall within the scope of...
Read more >Custom components - MUI System
Custom components. Learn how to use MUI System with custom components. Using sx with custom components. Normally you would use the Box component...
Read more >AWS Lambda – FAQs
Q : When should I use AWS Lambda versus Amazon EC2? ... You can invoke a Lambda function using a custom event through...
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
I never use the jsx pragma, and instead passthrough sx to the underlying theme-ui component, eg.
Yes,
sx
prop is transformed byjsx
pragma, similarly to how Emotion’s jsx pragma consumescss
prop.You can use any other prop name. If you want to reuse a name you’re already using,
style
should be okay, albeit a little confusing. I’d probably go withstyles
or pass justbackgroundColor
as a prop.