Skip to content

Instantly share code, notes, and snippets.

@AllGistsEqual
Last active May 1, 2020 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AllGistsEqual/9ea22cba3d723dd8a7a9f9facaa22558 to your computer and use it in GitHub Desktop.
Save AllGistsEqual/9ea22cba3d723dd8a7a9f9facaa22558 to your computer and use it in GitHub Desktop.
// ...
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