1
I’m making a Forms in React
and I need that after sending the form the same be rendered in a div
different showing the content to the user However the component Showforms
is not rendered and much less recognized, the terminal does not show me any error if you want, and all components are being properly called.
Follow the code excerpt below.
state = {
name: '',
tel: '',
email: '',
description: '',
formList: [],
}
Function when send button is clicked
saveForm = event => {
event.preventDefault()
const { state: { name, tel, email, description,formList } } = this
const regex = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
const emailValidation = regex.test(email)
if ((name === '') || ((tel === '') && (tel.length < 9)) || (email === '') || (description === '')) {
alert('Preencha todos os campos devidamente')
} else if (!emailValidation) {
alert('Email inválido, preencha corretamente')
} else {
formList.push(name, tel, email, description)
console.log(this.state.formList)
alert('Seu formulário foi enviado com sucesso! Nós agradeçemos seu contato!')
}
}
Call the components to be rendered in the DOM
{/*list's information */}
<div id='descriptionConteiner'>
{this.state.formList.map((list,index)=>{
return <ShowForm key={`${list}-${index}`} list={list} index={index}/>
})}
</div>
The Showform component is as follows:
import React from 'react'
const ShowForm = props => {
return <div>{props.list}</div>
}
export default ShowForm
The console.log(this.state.formList) is:
The summary of the components is : (according to the component "Showforms") is not even found
You’re not rendering what? what’s inside
formList
?return <div>{props.list}</div>
That didn’t render anything!– novic
@novic exactly the content of formList is not passed to the component through the map. I don’t know why =(
– LucasRussi
what’s inside the
formList
?– novic
the content within the formlist, the formlist is an array that stores status inputs (name,email,tel, Description) after saving via the formlist.push function. The contents inside the formlist are simple strings
– LucasRussi
save values? then demonstrate in your question with a console.log? I’m not seeing, there is no way!
console.log(this.state.formList)
?– novic
@novic i edited the post with the console.log(this.state.formList) after the save button was clicked
– LucasRussi
ah I’ve understood your mistake, you have not changed the state you can not do so! understood.?
– novic
Get @novic, thanks for your help!!!!!
– LucasRussi
I made the example!
– novic