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 figure out how I can pass in the value that just got changed, into my onChange dispatch handler.
Attempts
I have 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 }
}
The actions get called, but coutner is always set to the initial value.