-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix passing props arrow function directly to styled not working (#1633)
* Fix passing props arrow function directly to styled not working * Make formatting a bit nicer * Add changeset * Add tests * Add tsx syntax highlighting to changeset * Fix prettier warning in changeset
- Loading branch information
Showing
4 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- | ||
'@compiled/babel-plugin': patch | ||
--- | ||
|
||
Previously, if you passed `props => ...` directly to `styled.div` or `css()`, and the return value of the arrow function was an object, you would cause `@compiled/babel-plugin` to crash: | ||
|
||
```tsx | ||
import { styled } from '@compiled/react'; | ||
import React from 'react'; | ||
|
||
const Component = styled.div((props) => ({ | ||
color: `${props.customColor}`, | ||
background: props.background, | ||
})); | ||
``` | ||
|
||
While at the same time, wrapping the return value inside a logical expression or ternary expression would make it work perfectly fine: | ||
|
||
```tsx | ||
const Styles = styled.div((props) => | ||
props.isEditing ? {} : { backgroundColor: props.highlightColor } | ||
); | ||
``` | ||
|
||
With this version, both of these forms will work without issue. :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters