samedi 7 août 2021

How to uncheck a checkbox when onChangeText value changes?

Like mentioned in the title, I'm trying to have it so that when I type something in the text input field, the (already) checked box automatically. How should I go about doing this?

Any thought's and/or suggestions would be greatly appreciated!

Here's the code below

const handleSameUser = useCallback(() => {
const newState = !sameUser
setSameUser(newState);
if (newState && user) {
  handleInstructor({
    fullname: user?.fullname,
    email: user?.email,
    avatar: user?.avatar,
    isSameUser: true,
    // avatar: instructor?.avatar
 });
} else {
  handleInstructor({ avatar: instructor?.avatar, isSameUser: false });
}
}, [sameUser, setSameUser, user]);


return (

    <Checkbox
      transparent
      checked={sameUser}
      style=
      label="Use same details as user"
      onPress={() => handleSameUser()}
    />

   <Input
      defaultValue={details?.instructor?.fullname}
      placeholder="Full name"
      onChangeText={(value) => handleInstructor({ fullname: value, isSameUser: false })}

    />


  )

Thanks in advance




Aucun commentaire:

Enregistrer un commentaire