First click dont update the value in React

Viewed 32

I am working on an application that updates certain parameters entered.

Once entered (or not) these parameters go through a validation function before making the post to the api that takes care of that job.

The problem is that when the application enters the function that performs the post, the variable that validates that all the data is correct is still null.

This is the funcion to update.


    const updateLeads = async () => {
        validate();
        if (functionValidation) {
            const arrayLeadId = leads.split('\n');
            arrayLeadId.map(async function (leadId) {
                const formattedData = formatData(leadId, finalPipeline, finalStatus, user, tag);
                await pipelineServices.updateLeads(formattedData, token).then(resp => console.log(resp));
            });
        }else
        ;


    }

This is the function to validate


    const validate = () => {
        if((tokenValidation == true) && (leadListValidation == true)) {
            console.log("token y lead list validados");
            //si checked1 esta activo deben estarlo final pipeline y status final
            if ((checked1 == true)) {
                if ((finalPipelineValidation == true) && (statusFinalValidation == true)) {
                    setFunctionValidation(true);
                } else {
                    setFunctionValidation(false);
                }
            }

            //si checked2 esta activo debe estarlo designar responsable 
            if ((checked2 == true)) {
                if (responsibleValidation == true) {
                    setFunctionValidation(true);
                } else {
                    setFunctionValidation(false);
                }
            }

            //si checked3 esta activo debe estarlo tag 
            if ((checked3 == true)) {
                if (tagValidation == true) {
                    setFunctionValidation(true);
                } else {
                    setFunctionValidation(false);
                }
            }
        }else{
            setFunctionValidation(false);
        }

    }

0 Answers
Related