Skip to content

Instantly share code, notes, and snippets.

@despairblue
Last active September 10, 2015 16:17
Show Gist options
  • Select an option

  • Save despairblue/4ae15b40bc47d8efc2af to your computer and use it in GitHub Desktop.

Select an option

Save despairblue/4ae15b40bc47d8efc2af to your computer and use it in GitHub Desktop.
one off actions
function onError (field) {
this.refs[field].focus()
}
<Button onPress={() => this.props.register(this.state, onError)}>
Or Register
</Button>
function register ({username, password, email}, cb) {
return (dispatch, getState) => {
dispatch(requestRegister())
return fetch(API_REGISTER_URL}, {
method: 'POST',
headers,
body: JSON.stringify({
username,
email,
password
})
})
.then(response => response.json())
.catch(error => console.error(error.message))
.done(json => {
if (json.success) {
dispatch(receiveRegister(json))
} else if (json.data.errors.email) {
dispatch(failRegister('Invalid email.'))
cb('email')
} else if (json.data.errors.username) {
dispatch(failRegister('Invalid username.'))
cb('username')
}
})
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment