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))
}
}
}
export function baseSalaryChange(baseSalary) {
return { type: BASE_SALARY_CHANGED, baseSalary }
}
Actions are invoked, but coutner is always set to its initial value.
source
share