Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

222
Vistas
Am not able to edit the form values (crud React)
import React from 'react';

class InfoForm extends React.Component {
    constructor() {
        super();
        this.state={
            _id:'',
            Name:'',
            Age:'',
            isEdit:false
        }
    }

    infoChange = event =>{
        const {name,value} = event.target;
        this.setState({
            [name]:value
        })
    }
    infoSubmit = event => {
        if(!this.state.isEdit){
            let data = {
                isEdit:this.state.isEdit,
                Name:this.state.Name,
                Age:this.state.Age
            }
            this.props.myData(data);
        }
        else{
            let data = {
                isEdit:this.state.isEdit,
                _id:this.state._id,
                Name:this.state.Name,
                Age:this.state.Age
            }
            this.props.myData(data);
        }
    }

    static getDerivedStateFromProps(props, state) {
        if(props.setForm._id !== null)
        {
            return{
                isEdit:true,
                _id : props.setForm._id,
                Name:props.setForm.Name,
                Age:props.setForm.Age
            }
        }
        return null
    }
    render() {
        return (
            <form onSubmit={this.infoSubmit} autoComplete="off">
                <div className="form-group">
                    <label>Email Name:</label>
                    <input type="text" className="form-control" placeholder="Enter Name"
                           onChange={this.infoChange} name="Name" value={this.state.Name}
                    />
                </div>
                <div className="form-group">
                    <label>Email Age:</label>
                    <input type="text" className="form-control" placeholder="Enter Age"
                           onChange={this.infoChange} name="Age" value={this.state.Age}
                    />
                </div>
                <button type="submit" className="btn btn-primary">{this.state.isEdit ? 'update': 'Submit'}</button>
            </form>
        )
    }
}
export default InfoForm;

Form inputs wont allow to edit the values. when i click button this error occuring "Warning: A component is changing an uncontrolled input to be controlled. This is likely caused by the value changing from undefined to a defined value, which should not happen. Decide between using a controlled or uncontrolled input element for the lifetime of the component." please help me am new to react.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda