File tree 3 files changed +103
-1
lines changed
docs/src/pages/components/no-ssr
3 files changed +103
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,13 @@ const useStyles = makeStyles({
10
10
} ) ;
11
11
12
12
function LargeTree ( ) {
13
- return Array . from ( new Array ( 3000 ) ) . map ( ( _ , index ) => < span key = { index } > .</ span > ) ;
13
+ return (
14
+ < >
15
+ { Array . from ( new Array ( 3000 ) ) . map ( ( _ , index ) => (
16
+ < span key = { index } > .</ span >
17
+ ) ) }
18
+ </ >
19
+ ) ;
14
20
}
15
21
16
22
function FrameDeferring ( ) {
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { makeStyles } from '@material-ui/core/styles' ;
3
+ import NoSsr from '@material-ui/core/NoSsr' ;
4
+
5
+ const useStyles = makeStyles ( {
6
+ container : {
7
+ maxWidth : 300 ,
8
+ wordBreak : 'break-all' ,
9
+ } ,
10
+ } ) ;
11
+
12
+ function LargeTree ( ) {
13
+ return (
14
+ < >
15
+ { Array . from ( new Array ( 3000 ) ) . map ( ( _ , index ) => (
16
+ < span key = { index } > .</ span >
17
+ ) ) }
18
+ </ >
19
+ ) ;
20
+ }
21
+
22
+ function FrameDeferring ( ) {
23
+ const classes = useStyles ( ) ;
24
+ const [ state , setState ] = React . useState ( { open : false , defer : false } ) ;
25
+
26
+ return (
27
+ < div >
28
+ < button
29
+ type = "button"
30
+ onClick = { ( ) =>
31
+ setState ( {
32
+ open : ! state . open ,
33
+ defer : false ,
34
+ } )
35
+ }
36
+ >
37
+ { 'Render NoSsr defer="false"' }
38
+ </ button >
39
+ < button
40
+ type = "button"
41
+ onClick = { ( ) =>
42
+ setState ( {
43
+ open : ! state . open ,
44
+ defer : true ,
45
+ } )
46
+ }
47
+ >
48
+ { 'Render NoSsr defer="true"' }
49
+ </ button >
50
+ { state . open ? (
51
+ < div className = { classes . container } >
52
+ < span > Outside NoSsr</ span >
53
+ < NoSsr defer = { state . defer } >
54
+ ....Inside NoSsr
55
+ < LargeTree />
56
+ </ NoSsr >
57
+ </ div >
58
+ ) : null }
59
+ </ div >
60
+ ) ;
61
+ }
62
+
63
+ export default FrameDeferring ;
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import { withStyles } from '@material-ui/core/styles' ;
3
+ import { WithStyles } from '@material-ui/styles' ;
4
+ import NoSsr from '@material-ui/core/NoSsr' ;
5
+ import Button from '@material-ui/core/Button' ;
6
+
7
+ const styles = ( theme : any ) => ( {
8
+ button : {
9
+ display : 'block' ,
10
+ margin : theme . spacing ( 2 ) ,
11
+ } ,
12
+ } ) ;
13
+
14
+ export interface iProps extends WithStyles < typeof styles > { }
15
+
16
+ function SimpleNoSsr ( props : iProps ) {
17
+ const { classes } = props ;
18
+
19
+ return (
20
+ < div >
21
+ < Button className = { classes . button } variant = "contained" color = "primary" >
22
+ Server & Client
23
+ </ Button >
24
+ < NoSsr >
25
+ < Button className = { classes . button } variant = "contained" color = "secondary" >
26
+ Client only
27
+ </ Button >
28
+ </ NoSsr >
29
+ </ div >
30
+ ) ;
31
+ }
32
+
33
+ export default withStyles ( styles ) ( SimpleNoSsr ) ;
You can’t perform that action at this time.
0 commit comments