Initializing default values of a React hook form using Redux state

Viewed 1014

I am having a hard time assigning a default value to a React hook form using a React Redux object.

I am using react-hook-form, Redux toolkit, and materiauli. It appears that the problem is with the TextField of materialui, but I can't still solve it.

Initialization

const dispatch = useDispatch()
const category = useSelector(state => state.inventory.categories.category)

useEffect(() => {
  dispatch(getCategoryData(id))
}, [])

Initialization of React Hook Form

const { register, handleSubmit, reset } = useForm({
  defaultValues: {
    name: category.name
  }
})

JSX is not working

< TextField
  name='name'
  id='name'
  label='name'
  variant='outlined'
  InputLabelProps={{
    shrink: true,
  }}
  className={classes.form__item}
  inputRef={register}
/>
0 Answers
Related