Skip to content

Best way to handle Themed.X as={component} now? #2228

Answered by hasparus
ehowey asked this question in Q&A
Discussion options

You must be logged in to vote

Take note that Object.assign mutates its first parameter, so if you want to use it instead of spread operator, you'd rather do this `

Object.assign({} /* <- empty object */, one, two, three)

I tried a few different ways of using a spread operator but didn't get the syntax right.

Spread syntax in this case looks like the following:

<Link to="/link"  sx={(t) => ({ ...t.buttons.primary, fontSize: 3 })}>Button</Link>

You gotta wrap that object in parentheses (), because the curly bracket right after arrow => { get's parsed as block, not as object literal.

What might also work in this case, is sx.variant.

<Link to="/link" sx={{ variant: "buttons.primary", fontSize: 3 }}>Button<Link>

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ehowey
Comment options

Answer selected by ehowey
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