11import * as React from "react" ;
22import { Link } from "react-router-dom" ;
33import { withRouter , RouteComponentProps } from "react-router-dom" ;
4- import { withStyles , createStyles , WithStyles } from "@material-ui/core/styles" ;
4+ import makeStyles from "@material-ui/styles/makeStyles" ;
5+ import createStyles from "@material-ui/styles/createStyles" ;
56import Card from "@material-ui/core/Card" ;
67import CardHeader from "@material-ui/core/CardHeader" ;
78import CardContent from "@material-ui/core/CardContent" ;
@@ -18,16 +19,17 @@ import {
1819import { loginFormValidation } from "./loginPage.validation" ;
1920import { TextFieldForm } from "../common" ;
2021
21- // https://material-ui.com/guides/typescript/
22- const styles = theme =>
22+ // https://material-ui.com/styles/api/#makestyles-styles-options-hook
23+ const useStyles = makeStyles ( theme =>
2324 createStyles ( {
2425 card : {
2526 maxWidth : 400 ,
2627 margin : "0 auto"
2728 }
28- } ) ;
29+ } )
30+ ) ;
2931
30- interface Props extends RouteComponentProps , WithStyles < typeof styles > { }
32+ interface Props extends RouteComponentProps { }
3133
3234const LoginPageInner = ( props : Props ) => {
3335 const [ loginInfo , setLoginInfo ] = React . useState < LoginEntity > (
@@ -37,7 +39,7 @@ const LoginPageInner = (props: Props) => {
3739 createDefaultLoginFormErrors ( )
3840 ) ;
3941 const [ showLoginFailedMsg , setShowLoginFailedMsg ] = React . useState ( false ) ;
40- const { classes } = props ;
42+ const classes = useStyles ( ) ;
4143
4244 const onLogin = ( ) => {
4345 loginFormValidation . validateForm ( loginInfo ) . then ( formValidationResult => {
@@ -96,7 +98,7 @@ const LoginPageInner = (props: Props) => {
9698 ) ;
9799} ;
98100
99- export const LoginPage = withStyles ( styles ) ( withRouter < Props > ( LoginPageInner ) ) ;
101+ export const LoginPage = withRouter < Props > ( LoginPageInner ) ;
100102
101103interface PropsForm {
102104 onLogin : ( ) => void ;
@@ -105,7 +107,19 @@ interface PropsForm {
105107 loginFormErrors : LoginFormErrors ;
106108}
107109
110+ // https://material-ui.com/styles/api/#makestyles-styles-options-hook
111+ const useFormStyles = makeStyles ( theme =>
112+ createStyles ( {
113+ formContainer : {
114+ display : "flex" ,
115+ flexDirection : "column" ,
116+ justifyContent : "center"
117+ }
118+ } )
119+ ) ;
120+
108121const LoginForm = ( props : PropsForm ) => {
122+ const classes = useFormStyles ( ) ;
109123 const { onLogin, onUpdateField, loginInfo, loginFormErrors } = props ;
110124
111125 // TODO: Enhacement move this outside the stateless component discuss why is a good idea
@@ -114,13 +128,7 @@ const LoginForm = (props: PropsForm) => {
114128 } ;
115129
116130 return (
117- < div
118- style = { {
119- display : "flex" ,
120- flexDirection : "column" ,
121- justifyContent : "center"
122- } }
123- >
131+ < div className = { classes . formContainer } >
124132 < TextFieldForm
125133 label = "Name"
126134 name = "login"
0 commit comments