Skip to content
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

[docs] Add TS demos for SimpleNoSsr and FrameDeferring #17913

Merged
merged 6 commits into from
Oct 19, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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
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',
},
});

/**
* Changing the return value of this component to `any`
* As currently typescript does not support returning array from components
*
* https://github.com/DefinitelyTyped/DefinitelyTyped/issues/20356
*/
function LargeTree(): any {
return Array.from(new Array(3000)).map((_, index) => <span key={index}>.</span>);
oliviertassinari marked this conversation as resolved.
Show resolved Hide resolved
}

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;
32 changes: 32 additions & 0 deletions docs/src/pages/components/no-ssr/SimpleNoSsr.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import React from 'react';
import { withStyles, WithStyles } from '@material-ui/core/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);