Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

220
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!