Skip to content
This repository has been archived by the owner on Aug 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #200 from FormidableLabs/setmatchmedia-docs
Browse files Browse the repository at this point in the history
Add api docs for setMatchMedia
  • Loading branch information
ianobermiller committed Jun 9, 2015
2 parents 49a89f1 + 925bfd3 commit 7461b82
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions docs/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [Sample Style Object](#sample-style-object)
- [getState](#getstate)
- [keyframes](#keyframes)
- [Config.setMatchMedia](#config-setmatchmedia)
- [Style Component](#style-component)

## Radium
Expand Down Expand Up @@ -148,6 +149,30 @@ var styles = {
};
```

## Config.setMatchMedia

Allows you to replace the `matchMedia` function that Radium uses. The default is `window.matchMedia`, and the primary use case for replacing it is to use media queries on the server. You'll have to send the width and height of the page to the server somehow, and then use a [mock for match media](https://github.com/azazdeaz/match-media-mock) that implements the [`window.matchMedia` API](https://developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia). Your server code could look like this:

```as
var Radium = require('radium');
var matchMediaMock = require('match-media-mock').create();
Radium.Config.setMatchMedia(matchMediaMock);
app.get('/app/:width/:height', function(req, res) {
matchMediaMock.setConfig({
type: 'screen',
width: req.params.width,
height: req.params.height,
});
var html = React.renderToString(<RadiumApp/>);
res.end(html);
});
```

See #146 for more info.

## Style Component

The `<Style>` component renders an HTML `<style>` tag containing a set of CSS rules. Using it, you can define an optional `scopeSelector` that all selectors in the resulting `<style>` element will include.
Expand Down

0 comments on commit 7461b82

Please sign in to comment.