File tree Expand file tree Collapse file tree 4 files changed +51
-26
lines changed Expand file tree Collapse file tree 4 files changed +51
-26
lines changed Original file line number Diff line number Diff line change 1
1
import React from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
3
4
- const Home = ( { user, handleSignOut } ) => {
4
+ import SignOutContainer from '../../containers/SignOutContainer' ;
5
+
6
+ const Home = ( { user } ) => {
5
7
return (
6
8
< div >
7
9
< h1 > Home</ h1 >
8
10
< p > First Name: { user . firstName } </ p >
9
11
< p > Last Name: { user . lastName } </ p >
10
12
< p > Email: { user . email } </ p >
11
- < button onClick = { handleSignOut } > Sign Out </ button >
13
+ < SignOutContainer / >
12
14
</ div >
13
15
) ;
14
16
} ;
15
17
16
18
Home . propTypes = {
17
- user : PropTypes . object . isRequired ,
18
- handleSignOut : PropTypes . func . isRequired
19
+ user : PropTypes . object . isRequired
19
20
} ;
20
21
21
22
export default Home ;
Original file line number Diff line number Diff line change
1
+ import React from 'react' ;
2
+ import PropTypes from 'prop-types' ;
3
+
4
+ const SignOut = ( { handleSignOut } ) => {
5
+ return < button onClick = { handleSignOut } > Sign Out</ button > ;
6
+ } ;
7
+
8
+ SignOut . propTypes = {
9
+ handleSignOut : PropTypes . func . isRequired
10
+ } ;
11
+
12
+ export default SignOut ;
Original file line number Diff line number Diff line change 1
1
import React , { Component } from 'react' ;
2
- import { compose } from 'redux' ;
3
2
import { connect } from 'react-redux' ;
4
- import { removeUser } from '../../actions' ;
5
- import { withFirebase } from '../../services/firebase' ;
6
3
7
4
import Home from '../../components/Home' ;
8
5
9
6
class HomeContainer extends Component {
10
- handleSignOut = ( ) => {
11
- const { firebase, removeUser } = this . props ;
12
-
13
- firebase
14
- . signOut ( )
15
- . then ( ( ) => {
16
- removeUser ( ) ;
17
- } )
18
- . catch ( error => {
19
- const errorMessage = error . message ;
20
- console . log ( errorMessage ) ;
21
- } ) ;
22
- } ;
23
-
24
7
render ( ) {
25
- return < Home user = { this . props . user } handleSignOut = { this . handleSignOut } /> ;
8
+ return < Home user = { this . props . user } /> ;
26
9
}
27
10
}
28
11
29
12
const mapStateToProps = state => {
30
13
return { user : state . user } ;
31
14
} ;
32
15
33
- export default compose (
34
- connect ( mapStateToProps , { removeUser } ) ,
35
- withFirebase
36
- ) ( HomeContainer ) ;
16
+ export default connect ( mapStateToProps ) ( HomeContainer ) ;
Original file line number Diff line number Diff line change
1
+ import React , { Component } from 'react' ;
2
+ import { compose } from 'redux' ;
3
+ import { connect } from 'react-redux' ;
4
+ import { removeUser } from '../../actions' ;
5
+ import { withFirebase } from '../../services/firebase' ;
6
+
7
+ import SignOut from '../../components/SignOut' ;
8
+
9
+ class SignOutContainer extends Component {
10
+ handleSignOut = ( ) => {
11
+ const { firebase, removeUser } = this . props ;
12
+
13
+ firebase
14
+ . signOut ( )
15
+ . then ( ( ) => {
16
+ removeUser ( ) ;
17
+ } )
18
+ . catch ( error => {
19
+ const errorMessage = error . message ;
20
+ console . log ( errorMessage ) ;
21
+ } ) ;
22
+ } ;
23
+
24
+ render ( ) {
25
+ return < SignOut handleSignOut = { this . handleSignOut } /> ;
26
+ }
27
+ }
28
+
29
+ export default compose (
30
+ connect ( null , { removeUser } ) ,
31
+ withFirebase
32
+ ) ( SignOutContainer ) ;
You can’t perform that action at this time.
0 commit comments