Skip to content

Add documentation for including styles that use the value of a prop #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,35 @@ export default withStyles(({ color, unit }) => ({

`className` and `style` props must not be used on the same elements as `css()`.

### Using the value of a prop / high cardinality

To include styles that use the value of a prop (or any other styles that have a high cardinality and shouldn't be in a themed stylesheet), you can use inline styles in conjunction with `withstyles()`.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

withstyles() => withStyles()


```jsx
function MyComponent({ bold, padding, styles }) {
const {
backgroundImageUrl,
} = this.props;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a stateless functional component, this.props is not right. This should be destructured in the method signature along with the rest of the props.


return (
<div
{...css(
styles.container,
{ backgroundImage: `url(${backgroundImageUrl})` }
)}
>
Try to be a rainbow in{' '}
<a
href="/somewhere"
{...css(styles.link, bold && styles.link_bold)}
>
someone's cloud
</a>
</div>
);
}
```

## In the wild

[Organizations and projects using `react-with-styles`](INTHEWILD.md).
Expand Down