1- import React , { useEffect , useState } from "react" ;
1+ import React , { useEffect , useRef , useState } from "react" ;
22import PT from "prop-types" ;
33import { connect } from "react-redux" ;
44import Listing from "./Listing" ;
@@ -26,7 +26,16 @@ const Challenges = ({
2626 recommendedChallenges,
2727 initialized,
2828 updateQuery,
29+ userLoggedIn,
30+ isLoggedIn,
2931} ) => {
32+ const latestPropsRef = useRef ( null ) ;
33+ latestPropsRef . current = { userLoggedIn } ;
34+
35+ useEffect ( ( ) => {
36+ latestPropsRef . current . userLoggedIn ( ) ;
37+ } , [ ] ) ;
38+
3039 const BUCKET_OPEN_FOR_REGISTRATION = constants . FILTER_BUCKETS [ 1 ] ;
3140 const isRecommended = recommended && bucket === BUCKET_OPEN_FOR_REGISTRATION ;
3241 const sortByValue = isRecommended
@@ -76,6 +85,7 @@ const Challenges = ({
7685 } }
7786 bucket = { bucket }
7887 sortByLabels = { sortByLabels }
88+ isLoggedIn = { isLoggedIn }
7989 />
8090 </ >
8191 ) }
@@ -98,6 +108,7 @@ Challenges.propTypes = {
98108 recommendedChallenges : PT . arrayOf ( PT . shape ( ) ) ,
99109 initialized : PT . bool ,
100110 updateQuery : PT . func ,
111+ isLoggedIn : PT . bool ,
101112} ;
102113
103114const mapStateToProps = ( state ) => ( {
@@ -114,11 +125,13 @@ const mapStateToProps = (state) => ({
114125 recommended : state . filter . challenge . recommended ,
115126 recommendedChallenges : state . challenges . recommendedChallenges ,
116127 initialized : state . challenges . initialized ,
128+ isLoggedIn : state . lookup . isLoggedIn ,
117129} ) ;
118130
119131const mapDispatchToProps = {
120132 updateFilter : actions . filter . updateFilter ,
121133 updateQuery : actions . filter . updateChallengeQuery ,
134+ userLoggedIn : actions . lookup . isLoggedIn ,
122135} ;
123136
124137const mergeProps = ( stateProps , dispatchProps , ownProps ) => ( {
0 commit comments