Skip to main content

useUserProfile

This hook is used to get the user profile data. You can edit the user profile and change the password using this hook.

PropsTypeDescription
userObjectCurrent user object
firstNameStringFirst name of user( firstName set by setNewFirstName)
lastNameStringLast name of user (lastName set by setNewLastName)
emailStringEmail of user (email set by setNewEmail)
phoneStringPhone of user (phone set by setNewPhone)
setNewFirstNameFunctionState set function for first name
setNewLastNameFunctionState set function for last name
setNewEmailFunctionState set function for email
setNewPhoneFunctionState set function for phone
setNewPasswordFunctionState set function for password
setConfirmPasswordFunctionState set function for confirm password
updateProfileFunctionFunction to update profile. no params need to be passed
changePasswordFunctionFunction to update user Password no params need to be passed.
isLoadingBooleanReturns 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>
);
};