1
1
// prettier-ignore
2
- import { AppBar , Badge , Divider , Drawer as DrawerMui , Hidden , IconButton , List , ListItem , ListItemIcon , ListItemText , Toolbar , Typography , withWidth } from "@material-ui/core" ;
2
+ import { AppBar , Badge , Divider , Drawer as DrawerMui , Hidden , IconButton , List , ListItem , ListItemIcon , ListItemText , Toolbar , Typography , withWidth , useMediaQuery } from "@material-ui/core" ;
3
3
import { Theme } from "@material-ui/core/styles" ;
4
- import { isWidthUp , WithWidth } from "@material-ui/core/withWidth" ;
5
4
import FormatListNumberedIcon from "@material-ui/icons/FormatListNumbered" ;
6
5
import HomeIcon from "@material-ui/icons/Home" ;
7
6
import MenuIcon from "@material-ui/icons/Menu" ;
8
- import { makeStyles } from "@material-ui/styles" ;
7
+ import { makeStyles , useTheme } from "@material-ui/styles" ;
9
8
import * as React from "react" ;
10
- import { connect } from "react-redux" ;
11
- import { Route , RouteComponentProps , Router } from "react-router-dom" ;
9
+ import { Route , Router } from "react-router-dom" ;
12
10
import { history } from "./configureStore" ;
13
11
import { Todo } from "./model/model" ;
14
12
import HomePage from "./pages/HomePage" ;
15
13
import TodoPage from "./pages/TodoPage" ;
16
14
import { RootState } from "./reducers/index" ;
17
15
import withRoot from "./withRoot" ;
16
+ import { useSelector } from "react-redux" ;
18
17
19
18
function Routes ( ) {
20
19
const classes = useStyles ( ) ;
@@ -56,17 +55,13 @@ function Drawer(props: { todoList: Todo[] }) {
56
55
) ;
57
56
}
58
57
59
- interface Props extends RouteComponentProps < void > , WithWidth {
60
- todoList : Todo [ ] ;
61
- }
62
-
63
- function App ( props ?: Props ) {
58
+ function App ( ) {
64
59
const classes = useStyles ( ) ;
65
60
const [ mobileOpen , setMobileOpen ] = React . useState ( true ) ;
66
-
67
- if ( ! props ) {
68
- return null ;
69
- }
61
+ const todoList = useSelector ( ( state : RootState ) => state . todoList ) ;
62
+ const isMobile = useMediaQuery ( ( theme : Theme ) =>
63
+ theme . breakpoints . down ( "sm" )
64
+ ) ;
70
65
71
66
const handleDrawerToggle = ( ) => {
72
67
setMobileOpen ( ! mobileOpen ) ;
@@ -89,7 +84,7 @@ function App(props?: Props) {
89
84
< Typography
90
85
variant = "h6"
91
86
color = "inherit"
92
- noWrap = { isWidthUp ( "sm" , props . width ) }
87
+ noWrap = { isMobile }
93
88
>
94
89
Create-React-App with Material-UI, Typescript,
95
90
Redux and Routing
@@ -109,7 +104,7 @@ function App(props?: Props) {
109
104
keepMounted : true , // Better open performance on mobile.
110
105
} }
111
106
>
112
- < Drawer todoList = { props . todoList } />
107
+ < Drawer todoList = { todoList } />
113
108
</ DrawerMui >
114
109
</ Hidden >
115
110
< Hidden smDown >
@@ -120,7 +115,7 @@ function App(props?: Props) {
120
115
paper : classes . drawerPaper ,
121
116
} }
122
117
>
123
- < Drawer todoList = { props . todoList } />
118
+ < Drawer todoList = { todoList } />
124
119
</ DrawerMui >
125
120
</ Hidden >
126
121
< Routes />
@@ -189,10 +184,4 @@ const useStyles = makeStyles((theme: Theme) => ({
189
184
} ,
190
185
} ) ) ;
191
186
192
- function mapStateToProps ( state : RootState ) {
193
- return {
194
- todoList : state . todoList ,
195
- } ;
196
- }
197
-
198
- export default connect ( mapStateToProps ) ( withRoot ( withWidth ( ) ( App ) ) ) ;
187
+ export default withRoot ( App ) ;
0 commit comments