Skip to content

Commit

Permalink
[docs]:add ts demos for SimpleNoSsr and FrameDeferring
Browse files Browse the repository at this point in the history
  • Loading branch information
ganeshf22 committed Oct 17, 2019
1 parent ec7b5e9 commit 42ba28e
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 1 deletion.
8 changes: 7 additions & 1 deletion docs/src/pages/components/no-ssr/FrameDeferring.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ const useStyles = makeStyles({
});

function LargeTree() {
return Array.from(new Array(3000)).map((_, index) => <span key={index}>.</span>);
return (
<>
{Array.from(new Array(3000)).map((_, index) => (
<span key={index}>.</span>
))}
</>
);
}

function FrameDeferring() {
Expand Down
63 changes: 63 additions & 0 deletions docs/src/pages/components/no-ssr/FrameDeferring.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react';
import { makeStyles } from '@material-ui/core/styles';
import NoSsr from '@material-ui/core/NoSsr';

const useStyles = makeStyles({
container: {
maxWidth: 300,
wordBreak: 'break-all',
},
});

function LargeTree() {
return (
<>
{Array.from(new Array(3000)).map((_, index) => (
<span key={index}>.</span>
))}
</>
);
}

function FrameDeferring() {
const classes = useStyles();
const [state, setState] = React.useState({ open: false, defer: false });

return (
<div>
<button
type="button"
onClick={() =>
setState({
open: !state.open,
defer: false,
})
}
>
{'Render NoSsr defer="false"'}
</button>
<button
type="button"
onClick={() =>
setState({
open: !state.open,
defer: true,
})
}
>
{'Render NoSsr defer="true"'}
</button>
{state.open ? (
<div className={classes.container}>
<span>Outside NoSsr</span>
<NoSsr defer={state.defer}>
....Inside NoSsr
<LargeTree />
</NoSsr>
</div>
) : null}
</div>
);
}

export default FrameDeferring;
33 changes: 33 additions & 0 deletions docs/src/pages/components/no-ssr/SimpleNoSsr.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import { withStyles } from '@material-ui/core/styles';
import { WithStyles } from '@material-ui/styles';
import NoSsr from '@material-ui/core/NoSsr';
import Button from '@material-ui/core/Button';

const styles = (theme: any) => ({
button: {
display: 'block',
margin: theme.spacing(2),
},
});

export interface iProps extends WithStyles<typeof styles> {}

function SimpleNoSsr(props: iProps) {
const { classes } = props;

return (
<div>
<Button className={classes.button} variant="contained" color="primary">
Server & Client
</Button>
<NoSsr>
<Button className={classes.button} variant="contained" color="secondary">
Client only
</Button>
</NoSsr>
</div>
);
}

export default withStyles(styles)(SimpleNoSsr);

0 comments on commit 42ba28e

Please sign in to comment.