Autocomplete initial render
I previously asked you a problem which was, I want to modify only the data refine fills when Edit page loads only at initial time. iam modifying data on onChange and form submission but at initial render of the page, when refine fills the data, I want to modify only there
and you give me a code snippet:
import { useState, useEffect } from 'react';
import { useForm } from '@refinedev/core';
const PostEdit: React.FC = () => {
const { formMethods, formLoading, formError, formState } = useForm();
const [initialRender, setInitialRender] = useState(true);
useEffect(() => {
if (initialRender && formState?.data) {
// Modify the data here
formMethods.setValue('yourFieldName', 'yourModifiedValue');
setInitialRender(false);
}
}, [formState, formMethods, initialRender]);
// Rest of your component
};
this code works fine but when i click save button in the form even if it success or error, the form data going to old state
if i navigate away from edit page and come back no problem but if save and it redirected to list page now if i go toedit page again data is not setting id as value, also when i save and error occur data also resetting to old state
and you give me a code snippet:
import { useState, useEffect } from 'react';
import { useForm } from '@refinedev/core';
const PostEdit: React.FC = () => {
const { formMethods, formLoading, formError, formState } = useForm();
const [initialRender, setInitialRender] = useState(true);
useEffect(() => {
if (initialRender && formState?.data) {
// Modify the data here
formMethods.setValue('yourFieldName', 'yourModifiedValue');
setInitialRender(false);
}
}, [formState, formMethods, initialRender]);
// Rest of your component
};
this code works fine but when i click save button in the form even if it success or error, the form data going to old state
if i navigate away from edit page and come back no problem but if save and it redirected to list page now if i go toedit page again data is not setting id as value, also when i save and error occur data also resetting to old state
