@@ -121,26 +121,28 @@ _./src/pages/loginPage.tsx_
121121``` javascript
122122import * as React from " react" ;
123123import { withRouter , RouteComponentProps } from " react-router-dom" ;
124- import { withStyles , createStyles , WithStyles } from " @material-ui/core/styles" ;
124+ import makeStyles from " @material-ui/styles/makeStyles" ;
125+ import createStyles from " @material-ui/styles/createStyles" ;
125126import Card from " @material-ui/core/Card" ;
126127import CardHeader from " @material-ui/core/CardHeader" ;
127128import CardContent from " @material-ui/core/CardContent" ;
128129import TextField from " @material-ui/core/TextField" ;
129130import Button from " @material-ui/core/Button" ;
130131
131- // https://material-ui.com/guides/typescript/
132- const styles = theme =>
132+ // https://material-ui.com/styles/api/#makestyles-styles-options-hook
133+ const useStyles = makeStyles ( theme =>
133134 createStyles ({
134135 card: {
135136 maxWidth: 400 ,
136137 margin: " 0 auto"
137138 }
138- });
139+ })
140+ );
139141
140142interface Props extends RouteComponentProps, WithStyles< typeof styles> {}
141143
142144const LoginPageInner = (props : Props ) => {
143- const { classes } = props ;
145+ const classes = useStyles () ;
144146
145147 return (
146148 < Card className= {classes .card }>
@@ -164,7 +166,7 @@ const LoginPageInner = (props: Props) => {
164166 );
165167};
166168
167- export const LoginPage = withStyles (styles)( withRouter< Props> ( LoginPageInner)) ;
169+ export const LoginPage = withRouter < Props > LoginPageInner;
168170```
169171
170172- This can be ok, but if we take a deeper look to this component, we could break down into two, one is the card itself the other the form dialog, so it should finally look like:
@@ -248,16 +250,17 @@ _./src/pages/login/loginPage.tsx_
248250``` diff
249251// ...
250252
251- // https://material-ui.com/guides/typescript/
252- const styles = theme => createStyles({
253- card: {
254- maxWidth: 400,
255- margin: '0 auto',
256- },
257- });
253+ // https://material-ui.com/styles/api/#makestyles-styles-options-hook
254+ const useStyles = makeStyles(theme =>
255+ createStyles({
256+ card: {
257+ maxWidth: 400,
258+ margin: "0 auto"
259+ }
260+ })
261+ );
258262
259- interface Props extends RouteComponentProps, WithStyles<typeof styles> {
260- }
263+ interface Props extends RouteComponentProps {}
261264
262265const LoginPageInner = (props) => {
263266 const { classes } = props;
@@ -277,7 +280,7 @@ const LoginPageInner = (props) => {
277280 )
278281}
279282
280- export const LoginPage = withStyles(styles)( withRouter<Props>(LoginPageInner) );
283+ export const LoginPage = withRouter<Props>(LoginPageInner);
281284```
282285
283286- Let's add the navigation on button clicked (later on we will check for user and pwd) _ form.tsx_ .
@@ -462,23 +465,26 @@ import * as React from "react";
462465import Snackbar from " @material-ui/core/Snackbar" ;
463466import IconButton from " @material-ui/core/IconButton" ;
464467import CloseIcon from " @material-ui/icons/Close" ;
465- import { withStyles } from " @material-ui/core" ;
468+ import createStyles from " @material-ui/core/styles/createStyles" ;
469+ import makeStyles from " @material-ui/core/styles/makeStyles" ;
466470
467471interface Props {
468- classes?: any;
469472 message: string;
470473 show: boolean;
471474 onClose : () => void ;
472475}
473476
474- const styles = theme => ({
475- close: {
476- padding: theme .spacing .unit / 2
477- }
478- });
477+ const useStyles = makeStyles (theme =>
478+ createStyles ({
479+ close: {
480+ padding: theme .spacing (0.5 )
481+ }
482+ })
483+ );
479484
480- const NotificationComponentInner = (props : Props ) => {
481- const { classes , message , show , onClose } = props;
485+ export const NotificationComponent = (props : Props ) => {
486+ const { message , show , onClose } = props;
487+ const classes = useStyles ();
482488
483489 return (
484490 < Snackbar
@@ -507,10 +513,6 @@ const NotificationComponentInner = (props: Props) => {
507513 / >
508514 );
509515};
510-
511- export const NotificationComponent = withStyles (styles)(
512- NotificationComponentInner
513- );
514516```
515517
516518- Let's expose this common component via an _ index_ file.
@@ -535,7 +537,7 @@ const LoginPageInner = (props: Props) => {
535537 createEmptyLogin()
536538 );
537539+ const [showLoginFailedMsg, setShowLoginFailedMsg] = React.useState(false);
538- const { classes } = props ;
540+ const classes = useStyles() ;
539541
540542 const onLogin = () => {
541543 if (isValidLogin(loginInfo)) {
0 commit comments