Skip to content

Instantly share code, notes, and snippets.

@erick2014
Last active June 3, 2018 22:21
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 erick2014/0732ad0f1c5adbe029be83cf1f090a44 to your computer and use it in GitHub Desktop.
Save erick2014/0732ad0f1c5adbe029be83cf1f090a44 to your computer and use it in GitHub Desktop.
React Context api Consumer implementation
// 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