Last active
May 1, 2020 18:19
-
-
Save AllGistsEqual/9ea22cba3d723dd8a7a9f9facaa22558 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
import { connect } from 'react-redux' // #1 grab connect from react-redux | |
// ... | |
const SceneSplash = ({ isUserLoggedIn, navigation }) => { | |
const navigationTarget = isUserLoggedIn ? 'Home' : 'Login' // #2 determine path | |
useFocusEffect( | |
useCallback(() => { | |
const delayedNavigation = setTimeout(() => { | |
navigation.navigate(navigationTarget) // #3a replace 'login' with navigationTarget | |
}, 2000) | |
return () => clearTimeout(delayedNavigation) | |
}, []) | |
) | |
return ( // #3b replace 'login' with navigationTarget | |
<TouchableWrapper handlePress={() => navigation.navigate(navigationTarget)}> | |
// ... | |
</TouchableWrapper> | |
) | |
} | |
SceneSplash.propTypes = { | |
isUserLoggedIn: PropTypes.bool.isRequired, // #4 add propType | |
navigation: PropTypes.object.isRequired, | |
} | |
export default SceneSplash | |
const mapStateToProps = (state) => ({ | |
isUserLoggedIn: state.user.isLoggedIn, // #5 map stored value | |
}) | |
export default connect( | |
mapStateToProps, // #6 connect SceneSplash and add mapped state | |
)(SceneSplash) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment