-
Hello everyone, I am using React Hook Form 7.45.0 with an external controller component called React Number Format. Unfortunately, I'm struggling with an issue for a while and regardless of any solution I found on the internet, I'm still having this dev issue A snippet of my code is available here with the current issue running : https://codesandbox.io/s/cranky-sunset-dvzms6?file=/src/App.tsx This is driving me nuts aha Thank you for your insights ! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You're mixing both controlled and uncontrolled input APIs: <Controller
control={control}
+ name="zipcode"
+ rules={{
+ required: "À renseigner",
+ min: 5,
+ maxLength: 5
+ }}
- render={({ field: { onChange, value, ref } }) => (
+ render={({ field: { name, onChange, onBlur, value, ref } }) => (
<PatternFormat
getInputRef={ref}
+ value={value}
+ onBlur={onBlur}
+ name={name}
+ onValueChange={(value, sourceInfo) => {
+ onChange(value);
+ }
format="#####"
placeholder="75007"
id="zipcode"
/>
)}
- {...register("zipcode", {
- required: "À renseigner",
- min: 5,
- maxLength: 5
- })}
/> |
Beta Was this translation helpful? Give feedback.
You're mixing both controlled and uncontrolled input APIs:
Controller
andregister
respectively. Theref
warning you see is due to the fact that you are spreading the return values of theregister
function into theController
component, which is an RHF controlled input component and doesn't need to be registered.