-
The only way I've found to get defaultValues working is if the function is outside the React component and it's a hard-coded value or something from the global window object. However, I need to set a value for a React Select field from an async fetch() response and it's not working even though it's in the same format as the defaultValues hard-coded one is. I've been at this for a long while so any pointers would be really great. tyvm! === Because of having to be outside the component, I can't use React hooks like React Query so I just did a straight fetch() |
Beta Was this translation helpful? Give feedback.
Replies: 9 comments 14 replies
-
have you tried by just using |
Beta Was this translation helpful? Give feedback.
-
Correction, I see Here's my start: https://codesandbox.io/s/rhf-react-select-setvalue-98ns4?file=/src/index.js Find "getReactSelectDefault" in the code. |
Beta Was this translation helpful? Give feedback.
-
Sorry, I'm not following... so in my sandbox... go from this: <Controller
as={ReactSelect}
options={options}
name="ReactSelect"
isClearable
control={control}
defaultValue={getReactSelectDefault()}
/> to this? <Controller
as={ReactSelect}
options={options}
name="ReactSelect"
isClearable
control={control}
reset({...getReactSelectDefault(), {xxxx} })
/> |
Beta Was this translation helpful? Give feedback.
-
So upon initial form loading, reset entire form? What's the useEffect dependency? Have a sandbox link? |
Beta Was this translation helpful? Give feedback.
-
Sorry I'm needing extra help here :( I updated my CSB link as far along as I could get it but no dice. Thanks much for the extra hand-holding here. |
Beta Was this translation helpful? Give feedback.
-
I get that for reset's args, but I'm not even getting that far along. Would you please look at the CSB and correct it for me? |
Beta Was this translation helpful? Give feedback.
-
the |
Beta Was this translation helpful? Give feedback.
-
Out of curiosity, why does using an async function (vs non-async) cause the following error?
|
Beta Was this translation helpful? Give feedback.
the
useEffect
snippet was doing all that - no error now that it's commented out