Skip to content

What is the purpose of adding {...props} right before sx? #1310

Answered by lachlanjc
dungle-scrubs asked this question in Q&A
Discussion options

You must be logged in to vote

This syntax isn’t Theme UI-specific, it’s using a JavaScript “spread operator” to “forward” all props. That means if you’re passing children or DOM attributes or style props, they’ll be rendered on that styled div instead of ignored. It’s a common pattern with UI components (every one of Theme UI’s internal components uses it), so we don’t restrict what kinds of attributes you can use on those elements.

You can read more about its usage in React here: https://gist.github.com/sebmarkbage/07bbe37bc42b6d4aef81#spread-attributes

& on the operator itself: https://www.joshwcomeau.com/operator-lookup?match=restspread

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@dungle-scrubs
Comment options

@lachlanjc
Comment options

@maiertech
Comment options

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