Skip to content

Commit 6d030d6

Browse files
author
spoeck
committed
refactor: remove HoC widthWidth and connect
1 parent 9ec8672 commit 6d030d6

File tree

1 file changed

+13
-24
lines changed

1 file changed

+13
-24
lines changed

src/App.tsx

Lines changed: 13 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
// 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";
33
import { Theme } from "@material-ui/core/styles";
4-
import { isWidthUp, WithWidth } from "@material-ui/core/withWidth";
54
import FormatListNumberedIcon from "@material-ui/icons/FormatListNumbered";
65
import HomeIcon from "@material-ui/icons/Home";
76
import MenuIcon from "@material-ui/icons/Menu";
8-
import { makeStyles } from "@material-ui/styles";
7+
import { makeStyles, useTheme } from "@material-ui/styles";
98
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";
1210
import { history } from "./configureStore";
1311
import { Todo } from "./model/model";
1412
import HomePage from "./pages/HomePage";
1513
import TodoPage from "./pages/TodoPage";
1614
import { RootState } from "./reducers/index";
1715
import withRoot from "./withRoot";
16+
import { useSelector } from "react-redux";
1817

1918
function Routes() {
2019
const classes = useStyles();
@@ -56,17 +55,13 @@ function Drawer(props: { todoList: Todo[] }) {
5655
);
5756
}
5857

59-
interface Props extends RouteComponentProps<void>, WithWidth {
60-
todoList: Todo[];
61-
}
62-
63-
function App(props?: Props) {
58+
function App() {
6459
const classes = useStyles();
6560
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+
);
7065

7166
const handleDrawerToggle = () => {
7267
setMobileOpen(!mobileOpen);
@@ -89,7 +84,7 @@ function App(props?: Props) {
8984
<Typography
9085
variant="h6"
9186
color="inherit"
92-
noWrap={isWidthUp("sm", props.width)}
87+
noWrap={isMobile}
9388
>
9489
Create-React-App with Material-UI, Typescript,
9590
Redux and Routing
@@ -109,7 +104,7 @@ function App(props?: Props) {
109104
keepMounted: true, // Better open performance on mobile.
110105
}}
111106
>
112-
<Drawer todoList={props.todoList} />
107+
<Drawer todoList={todoList} />
113108
</DrawerMui>
114109
</Hidden>
115110
<Hidden smDown>
@@ -120,7 +115,7 @@ function App(props?: Props) {
120115
paper: classes.drawerPaper,
121116
}}
122117
>
123-
<Drawer todoList={props.todoList} />
118+
<Drawer todoList={todoList} />
124119
</DrawerMui>
125120
</Hidden>
126121
<Routes />
@@ -189,10 +184,4 @@ const useStyles = makeStyles((theme: Theme) => ({
189184
},
190185
}));
191186

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

Comments
 (0)