Last active
June 3, 2018 22:21
-
-
Save erick2014/0732ad0f1c5adbe029be83cf1f090a44 to your computer and use it in GitHub Desktop.
React Context api Consumer implementation
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
// Session Actions | |
export const setSessionInfo = data => { | |
return { | |
payload: data, | |
type: SESSION_SET_USER_INFO | |
} | |
} | |
// Login Comp | |
onClickLoginBtn = dispatch => { | |
const { state: { user, pass }, props: { navigation: { navigate } } } = this | |
if (user !== '' && pass !== '') { | |
const loginUser = async () => { | |
result = await authUser(this.state) | |
if (!result['error']) { | |
//dispatch action to set the session info in global state | |
dispatch(setSessionInfo(result)) | |
} else { | |
console.log('error ', result['error']) | |
} | |
} | |
loginUser() | |
} | |
} | |
return ( | |
<AppConsumer> | |
{({ dispatch, sessionData }) => { | |
<View style={styles.inputBox}> | |
<Button onPress={() => { this.onClickLoginBtn(dispatch) }} title="Ingresar" color="#46912F" /> | |
</View> | |
}} | |
</AppConsumer> | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment