I have controlled input where i set value from redux, how do I set onChange
handler here
<input type="text" className="form-control"
name="name" placeholder="full name"
value={user.name} onChange={??} />
I have controlled input where i set value from redux, how do I set onChange
handler here
<input type="text" className="form-control"
name="name" placeholder="full name"
value={user.name} onChange={??} />
As user
data is a part of redux's store, you update it's value by dispatching an action.
With hooks you use useDispatch
:
import React from "react";
import { useDispatch } from "react-redux";
export const CounterComponent = ({ value }) => {
const dispatch = useDispatch();
const onChange = (e) => dispatch({ type: `USER_NAME`, name: e.target.value });
return (
<input
type="text"
className="form-control"
name="name"
placeholder="full name"
value={user.name}
onChange={onChange}
/>
);
};