import { FC , useEffect } from 'react' ; import { Redirect , RouteComponentProps } from 'react-router-dom' ; import { LocalStorage } from 'utils' ; import { connect , ConnectedProps } from 'react-redux' ; import { AppState } from 'store' ; import { keepLogin } from 'store/user/actions' ; const mapState = ( { user } ) => ( { user , } ) ; const mapDispatch = { keepLogin , } ; const connector = connect ( mapState , mapDispatch ) ; type PropsFromRedux = ConnectedProps < typeof connector > ; const Home = ( { user , keepLogin , } ) => { useEffect ( ( ) => { const userId = LocalStorage . get ( 'userId' ) ; const username = LocalStorage . get ( 'username' ) ; if ( userId && username && ! user . userId ) { keepLogin ( { userId , username } ) ; } } , [ ] ) ; return user . userId ? < Redirect to = "/todo" / > : < Redirect to = "/login" / > ; } ; export default connector ( Home ) ;