edit form submit
I have a useEffect in my Autocomplete component
useEffect(() => {
if (
initialReturnValueTransformer &&
initialRender &&
useFormProps?.formState.defaultValues &&
useFormProps?.refineCore.formLoading === false
) {
const initialVal = useFormProps?.getValues && useFormProps?.getValues(name);
console.log(useFormProps.refineCore.formLoading, "llll");
console.log("heree");
setSelectedOption(initialVal);
fieldRef?.current?.onChange(
initialReturnValueTransformer && initialReturnValueTransformer(initialVal)
);
setInitialRender(false);
}
}, [useFormProps?.formState]);
in my edit page, iam setting value to its id at initial render. noiw when I submit the form and after success, i came to same edit page and try submit again then the value is not transforming or transformed value is reverting
3 Replies
Hi @alfaz_muhammed. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
----------------------
Based on the information provided in the extracts, it seems like you're using the
useForm
hook from Refine in your component. The useForm
hook provides a refineCore
object that contains several properties, including formLoading
and queryResult
.
The formLoading
property indicates the loading state of the form request. If formLoading
is false
, it means that the form request has completed. The queryResult
property contains the result of the query of a record.
In your useEffect
hook, you're checking if formLoading
is false
before setting the selected option and calling the onChange
method. This suggests that you're waiting for the form request to complete before updating the selected option.
If the value is not transforming or the transformed value is reverting when you submit the form and navigate back to the edit page, it could be due to the state of the form or the component not being preserved between navigations.
You might want to check the following:
1. Ensure that the useForm
hook is being called with the correct parameters. For example, if you're editing a post, you should pass the id of the post to the useForm
hook.
2. Check the logic in your useEffect
hook. Make sure that the conditions for setting the selected option and calling the onChange
method are correct.
3. Check the initialReturnValueTransformer
function. Make sure that it's returning the expected value.
4. Check the state of the form and the component when you navigate back to the edit page. If the state is not being preserved, you might need to use a state management solution or persist the state in some way.
Unfortunately, without more specific information or code, it's difficult to provide a more precise answer. You might find it helpful to refer to the Refine documentation (https://refine.dev/docs) for more information on how to use the useForm
hook and other features of Refine.
----------------------
Note: you can ask me a follow up question by @ mentioning me again
:speech_balloon:
----------------------<@763439201353596968> kapa.ai is still learning and improving, please let us know how it did by reacting below
extended-salmon•14mo ago
Hello @alfaz_muhammed , unfortunately, it's not feasible to debug this solely with the
useEffect
code snippet. It seems like there's a lot of custom logic involved and you're using ref
. If you share a reproducible example, we will try to help with debugging.