useUserProfile
This hook is used to get the user profile data. You can edit the user profile and change the password using this hook.
Props | Type | Description |
---|---|---|
user | Object | Current user object |
firstName | String | First name of user( firstName set by setNewFirstName) |
lastName | String | Last name of user (lastName set by setNewLastName) |
email | String | Email of user (email set by setNewEmail) |
phone | String | Phone of user (phone set by setNewPhone) |
setNewFirstName | Function | State set function for first name |
setNewLastName | Function | State set function for last name |
setNewEmail | Function | State set function for email |
setNewPhone | Function | State set function for phone |
setNewPassword | Function | State set function for password |
setConfirmPassword | Function | State set function for confirm password |
updateProfile | Function | Function to update profile. no params need to be passed |
changePassword | Function | Function to update user Password no params need to be passed. |
isLoading | Boolean | Returns loading state of update. |
note
- State for each field is handled inside hooks ( refer example for details )
- Pass the props received in blocks into hook
Example on Updating user profile data
const UserProfileUpdate = (props) => {
const {
setNewFirstName,
setNewLastName,
setNewEmail,
setNewPhone,
firstName,
lastName,
email,
phone,
isLoading,
updateProfile,
} = useUserProfile(props);
return (
<View>
<Input
label="First Name"
placeholder="Enter your First Name"
onChangeText={setNewFirstName}
value={firstName}
style={[styles.input, styles.inputHeight]}
/>
<Input
label="Last Name"
placeholder="Enter your Last Name"
onChangeText={setNewLastName}
value={lastName}
style={[styles.input, styles.inputHeight]}
/>
<Input
label="Email"
placeholder="Email"
onChangeText={setNewEmail}
value={email}
style={[styles.input, styles.inputHeight]}
/>
<Input
label="Phone"
placeholder="Phone"
onChangeText={setNewPhone}
value={phone}
style={[styles.input, styles.inputHeight]}
/>
<Button onPress={updateProfile} loading={isLoading} status="dark">
Update Profile
</Button>
</View>
);
};
Example on Updating user Password
const UpdatePassword = (props) => {
const {
changePassword,
setNewPassword,
setConfirmPassword,
isLoading,
} = useUserProfile(props);
return (
<View>
<Input
label="Password"
placeholder="Enter new password"
onChangeText={setNewPassword}
style={[styles.input, styles.inputHeight]}
/>
<Input
label="Confirm password"
placeholder="Confirm password"
onChangeText={setConfirmPassword}
style={[styles.input, styles.inputHeight]}
/>
<Button onPress={changePassword} loading={isLoading} status="dark">
Update Profile
</Button>
</View>
);
};