Skip to content
This repository has been archived by the owner on Apr 25, 2021. It is now read-only.

Commit

Permalink
added entry in readme for stylesheet HoC
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis committed May 16, 2016
1 parent a27c50f commit 63810ae
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,51 @@ ReactDOM.render(
store.dispatch(calculateResponsiveState(window))
```

# Higher-Order Components

When building responsive applications in react, it's common to
implement styles for each breakpoint and then apply them like so:

```jsx
const commonStyle = {...}

const styles = {
element: {
...commonStyle,
color: 'blue',
},
elementThin: {
...commonStyle,
color: 'black',
}
}

// somewhere in your component...

<div style={browser.lessThan.medium ? styles.elementThing : styles.element} />
```

However this become very repetitive rather quickly. To help, redux-responsive
provides a higher-order component for managing these styles. The follow is
equivalent to the logic above:

```jsx
import {StyleSheet} from 'redux-responsive'

const stylesheet = {
element: {
color: 'blue',
_lessThan_medium: {
color: 'black',
}
}
}

const component = StyleSheet(stylesheet)(({styles}) => (
<div style={styles.element} />
))
```


# Versioning

Expand Down

0 comments on commit 63810ae

Please sign in to comment.