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

184
Views
cannot determine my onChange functions for my input fields

I have a state called workExp (an object) which has 6 attributes. I have a form that has 6 fields and I want to save the field values to the attteibutes of my workExp state. What I cannot figure out is what will my onchange for each input field look like?

My state:


export default class Resume extends Component {

    constructor() {
        super();
    
        this.state = {
        step: 1,
        firstName: '',
        lastName: '',
        email: '',
        phone: '',
        address: '',
        linkedIn: '',
        workExp: {        //this is the state I am concerned with
            jobTitle: '',
            city: '',
            employer: '',
            startDate:'',
            endDate: '',
            responsibilities: '',
            id: ''
        },
        workExpData: [],
        
    }
}

This is my form:

<form>

    <input type="text" className="form-control" id="jobtitle" aria-describedby="emailHelp" value= 
    {values.workExp.jobTitle}/>

     <input type="text" className="form-control" id="city" aria-describedby="emailHelp" value= 
    {values.workExp.city}}/>

    <input type="text" className="form-control" id="employer" value={values.workExp.employer} />

   <input type="text" className="form-control" id="startdate" value={values.workExp.startDate} />

   <input type="text" className="form-control" id="enddate" value={values.workExp.endDate}/>

   <textarea className="form-control" id="r&r" rows="3" value={values.workExp.responsibilities}></textarea>
      
</form>

I am fairly new to react so any help would be really appreciated. Cheers!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Use the spread operator and override the property as needed:

function onChangeWorkExpXXX(e) {
    this.setState({
        workExp: {
            ...workExp,
            XXX: e.target.value,
        },
    });
}

Where XXX could be something like the employer or endDate.

about 4 years ago · Juan Pablo Isaza Report

0

export default class Resume extends Component {

    constructor() {
        super();
    
        this.state = {
        step: 1,
        firstName: '',
        lastName: '',
        email: '',
        phone: '',
        address: '',
        linkedIn: '',
        workExp: {        //this is the state I am concerned with
            jobTitle: '',
            city: '',
            employer: '',
            startDate:'',
            endDate: '',
            responsibilities: '',
            id: ''
        },
        workExpData: [],
        
    }
}
<form>

    <input type="text" className="form-control" id="jobtitle" aria-describedby="emailHelp" value= 
    {values.workExp.jobTitle} onChange={e=>{
       let temp = {...this.state}
       temp.workExp.jobTitle = e.target.value ;
       this.setState({...temp})
    }}   />

     <input type="text" className="form-control" id="city" aria-describedby="emailHelp" value= 
    {values.workExp.city}}  onChange={e=>{
       let temp = {...this.state}
       temp.workExp.city = e.target.value ;
       this.setState({...temp})
    }} />

    <input type="text" className="form-control" id="employer" value={values.workExp.employer} onChange={e=>{
       let temp = {...this.state}
       temp.workExp.employer = e.target.value ;
       this.setState({...temp})
    }} />

   <input type="text" className="form-control" id="startdate" value={values.workExp.startDate} onChange={e=>{
       let temp = {...this.state}
       temp.workExp.startDate = e.target.value ;
       this.setState({...temp})
    }} />

   <input type="text" className="form-control" id="enddate" value={values.workExp.endDate}. onChange={e=>{
       let temp = {...this.state}
       temp.workExp.endDate = e.target.value ;
       this.setState({...temp})
    }} />

   <textarea className="form-control" id="r&r" rows="3" value={values.workExp.responsibilities} onChange={e=>{
       let temp = {...this.state}
       temp.workExp.responsibilities = e.target.value ;
       this.setState({...temp})
    }}   ></textarea>
      
</form>
about 4 years ago · Juan Pablo Isaza Report
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!