0

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={??} />
Lokesh Bajracharya
  • 457
  • 2
  • 8
  • 19

1 Answers1

0

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}
    />
  );
};
Dennis Vash
  • 50,196
  • 9
  • 100
  • 118