0

I am new to using useReducer, I need to write a reducer function for this. These will be hooked into text fields and I am trying to update the state this way.

    const [registerReq, updateRegister] = useReducer(registerReducer, {
    user: {
      firstName: "",
      lastName: "",
      jobTitle: "",
      email: "",
      phone: ""
    }
  }
  );

I can do it fine with a single object, but I cannot do it with a nested object.

here is the type I am using

export interface RegisterReq {

user: { firstName: string lastName: string jobTitle: string email: string phone: string } }

const registerReducer = (state: RegisterReq, update: Partial<RegisterReq>) => ({
  ...state,
  ...update
});

updater function

const updateFirstName: React.ChangeEventHandler<HTMLInputElement> = (evt) => {
updateRegister({ user: { firstName: evt.target.value }})

};

0 Answers0