0

I'm trying to create a simple form where a user enters basic information which gets posted to a database on submit. I check if my customer already exists in my database and if not I create a new customer. I'm new to React Native and React Hooks so maybe I'm violating one of the rules here, but when I pass the information into setCustomer to update the state nothing happens. Debugging show me the correct values are being passed to setCustomer. Any help would be appreciated.

const initialCustomerState = { email: "", firstName: "", lastName: ""}
export default function SendRequest(){
    
    const customers = getAllCustomers()
    const [customer,setCustomer] = useState(initialCustomerState)

    const {
            control, 
            handleSubmit,
            formState: {errors, isValid}
        } = useForm({mode: 'onBlur'})
    const onSubmit = data => {
        if(checkIfExists(data.email) == false){
            let email = data.email  
            let firstName = data.firstName
            let lastName = ''
            if(data.hasOwnProperty('lastName')){
                lastName = data.lastName
            }
            setCustomer(email,firstName,lastName)
            createNewCustomer()
            createNewReview(data.email)
            
        }else{
            createNewReview(data.email)
        }

    }

1 Answer 1

2

Your customer value is an object, you should place email,firstName,lastName inside curly brackets {email,firstName,lastName}

Sign up to request clarification or add additional context in comments.

1 Comment

Tried the curly brackets and still no update to the state setCustomer({email,firstName,lastName})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.