11import React from 'react' ;
22import { createRoot } from 'react-dom/client' ;
3- import { HashRouter as Router , Route , Switch , withRouter } from 'react-router-dom' ;
3+ import { HashRouter as Router , Route , Routes , useNavigate , useLocation } from 'react-router-dom' ;
44import { withStyles } from 'tss-react/mui' ;
55import ExamplesGrid from './ExamplesGrid' ;
66import examples from '../examples' ;
@@ -17,58 +17,52 @@ const styles = {
1717 } ,
1818} ;
1919
20- class Examples extends React . Component {
21- returnHome = ( ) => {
22- this . props . history . push ( '/' ) ;
23- } ;
20+ function Examples ( { classes } ) {
21+ const navigate = useNavigate ( ) ;
22+ const location = useLocation ( ) ;
2423
25- render ( ) {
26- const { classes } = this . props ;
24+ const defaultTheme = createTheme ( ) ;
25+ const returnHomeStyle = { padding : '0px' , margin : '20px 0 20px 0' } ;
2726
28- var returnHomeStyle = { padding : '0px' , margin : '20px 0 20px 0' } ;
29-
30- const defaultTheme = createTheme ( ) ;
31-
32- return (
33- < ThemeProvider theme = { defaultTheme } >
34- < main className = { classes . root } >
35- < div className = { classes . contentWrapper } >
36- < Switch >
37- < Route path = "/" exact render = { ( ) => < ExamplesGrid examples = { examples } /> } />
38- { Object . keys ( examples ) . map ( ( label , index ) => (
39- < Route
40- key = { index }
41- path = { `/${ label . replace ( / \s + / g, '-' ) . toLowerCase ( ) } ` }
42- exact
43- component = { examples [ label ] }
44- />
45- ) ) }
46- </ Switch >
47- < div >
48- { this . props . location . pathname !== '/' && (
49- < div style = { returnHomeStyle } >
50- < Button color = "primary" onClick = { this . returnHome } >
51- Back to Example Index
52- </ Button >
53- </ div >
54- ) }
55- </ div >
27+ return (
28+ < ThemeProvider theme = { defaultTheme } >
29+ < main className = { classes . root } >
30+ < div className = { classes . contentWrapper } >
31+ < Routes >
32+ < Route path = "/" element = { < ExamplesGrid examples = { examples } /> } />
33+ { Object . keys ( examples ) . map ( ( label , index ) => (
34+ < Route
35+ key = { index }
36+ path = { `/${ label . replace ( / \s + / g, '-' ) . toLowerCase ( ) } ` }
37+ element = { React . createElement ( examples [ label ] ) }
38+ />
39+ ) ) }
40+ </ Routes >
41+ < div >
42+ { location . pathname !== '/' && (
43+ < div style = { returnHomeStyle } >
44+ < Button color = "primary" onClick = { ( ) => navigate ( '/' ) } >
45+ Back to Example Index
46+ </ Button >
47+ </ div >
48+ ) }
5649 </ div >
57- </ main >
58- </ ThemeProvider >
59- ) ;
60- }
50+ </ div >
51+ </ main >
52+ </ ThemeProvider >
53+ ) ;
6154}
6255
63- const StyledExamples = withRouter ( withStyles ( Examples , styles ) ) ;
56+ const StyledExamples = withStyles ( Examples , styles ) ;
6457
6558function App ( ) {
6659 return (
67- < Router hashType = "noslash" >
60+ < Router >
6861 < StyledExamples />
6962 </ Router >
7063 ) ;
7164}
65+
7266const container = document . getElementById ( 'app-root' ) ;
7367const root = createRoot ( container ) ;
7468root . render ( < App /> ) ;
0 commit comments