-2
I have a ready front-end of a registration form, but they are working as follows: I do all the registration and when clicking on the button it calls the function that takes the values of the fields and Ste in a state variable with the respective names. After that I connect to the back-end through Xios, sending a post with the data to register. Now comes error, I click the button and does not send the first time, it is only going the second time I click and sometimes only the third, IE, it does not go first. I already looked at the back and it seems right to me, if you need to look at the code I can also send. NOTE: the password I am setting elsewhere.
Front code:
const [Senha, setSenha] = useState("")
const [Email, setEmail] = useState("")
const [CNPJ, setCNPJ] = useState("")
const [Nome, setNome] = useState("")
const [Cidade, setCidade] = useState("")
const [Estado, setEstado] = useState("")
const [Endereco, setEndereco] = useState("")
async function Registrar(value){
setEmail(document.getElementById("Email").value)
setCNPJ(document.getElementById("CNPJ").value)
setNome(document.getElementById("Nome").value)
setEndereco(document.getElementById("Endereco").value)
setCidade(document.getElementById("Cidade").value)
setEstado(document.getElementById("Estado").value)
if((Senha != "") && (Email != "") && (Cidade != "") && (Estado != "") && (Nome != "") && (CNPJ != "") && (Endereco != "")){
await api.post("/Cadastro",{
nomeCondominio: Nome,
cnpj: CNPJ,
endereco: Endereco,
Cidade: Cidade,
Email: Email,
Estado: Estado,
Senha: Senha
})
}
}
function receiving the data:
export const saveCondominio = async (request: Request, response: Response) =>{
console.log("Salvando os dados...")
console.log(request.body)
const con = await getRepository(condominio).save(request.body)
response.json(con)
}
Can I be going wrong? or capturing input data the wrong way?
programming wrong!
– novic