Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

607
Visualizações
Why is my React Hook State not updating when using setState?

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)
        }

    }
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda