Skip to content

Commit

Permalink
📝 render props doc for withWidth
Browse files Browse the repository at this point in the history
  • Loading branch information
JulienUsson committed Oct 6, 2018
1 parent e849589 commit aeee392
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/src/pages/layout/breakpoints/RenderPropsWithWidth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import withWidth from '@material-ui/core/withWidth';
import Typography from '@material-ui/core/Typography';
import toRenderProps from 'recompose/toRenderProps';

const WithWidth = toRenderProps(withWidth());

function WithWidthDemo() {
return (
<WithWidth>
{({ width }) => <Typography variant="subtitle1">Current width: {width}</Typography>}
</WithWidth>
);
}

export default WithWidthDemo;
7 changes: 7 additions & 0 deletions docs/src/pages/layout/breakpoints/breakpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ In the following demo, we change the rendered DOM element (*em*, <u>u</u>, ~~del

⚠️ `withWidth()` server-side rendering support is limited.

## Render Props

In some cases you could have prop name collisions using higher-order components.
In those cases you can use [render props](https://reactjs.org/docs/render-props.html) like in the following demo.

{{"demo": "pages/layout/breakpoints/RenderPropsWithWidth.js"}}

## API

### `withWidth([options]) => higher-order component`
Expand Down
7 changes: 7 additions & 0 deletions pages/layout/breakpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ module.exports = require('fs')
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/layout/breakpoints/WithWidth'), 'utf8')
`,
},
'pages/layout/breakpoints/RenderPropsWithWidth.js': {
js: require('docs/src/pages/layout/breakpoints/RenderPropsWithWidth').default,
raw: preval`
module.exports = require('fs')
.readFileSync(require.resolve('docs/src/pages/layout/breakpoints/RenderPropsWithWidth'), 'utf8')
`,
},
}}
Expand Down

0 comments on commit aeee392

Please sign in to comment.