React Redux - Sending input value to submit

I have the following React view / render function:

let BaseSalaryView = ({ counter, onChange }) => (
    <div>
        <input type="text"
            placeholder="Annual Salary"
            value={counter}
            onChange={() => onChange(counter)} />
        <span>Try: {counter}</span>
    </div>
)

I am trying to understand how I can pass the value that has just been changed to my onChange send handler.

Attempts

I tried the following, but they are all undefined.

onChange={() => onChange(this.input.value)}> 
onChange={() => onChange(input.value)}> 
onChange={() => onChange(value)}> 

Rest of code

const mapDispatchToProps = (dispatch) => {
    return {
        onChange: (counter) => {
            dispatch(baseSalaryChange(counter)) // Need the input v alue here
        }
    }
}

export function baseSalaryChange(baseSalary) {
  return { type: BASE_SALARY_CHANGED, baseSalary }
}

Actions are invoked, but coutner is always set to its initial value.

+1
source share
1 answer

OMG after 2 hours of fighting, 2 minutes after I posted a question that I found out.

onChange, ​​ event, . event.target :

onChange={(event) => onChange(event.target.value)} />
+4

Source: https://habr.com/ru/post/1681826/


All Articles