Let's say I have an input
component that will update the state from its onChange
handler.
function updateInputState(newvalue) {
return({
type: "UPDATE_INPUT_STATE",
payload: newValue
});
}
function InputComponent(props) {
function onChange(event) {
const newValue = event.target.value;
// OPTION #1 - WITHOUT AN ACTION CREATOR. DISPATCH THE ACTION DIRECTLY
dispatch({
type: "UPDATE_INPUT_STATE",
payload: newValue
});
// OPTION #2 - WITH AN ACTION CREATOR
dispatch(updateInputState(newValue));
}
return(
<input value={props.value} onChange={onchange}/>
);
}
I think option #2 is more readable, so why would I use an action creator instead of a regular action dispatch?