Closed Oui-Dev closed 6 months ago
@inertiajs/react
laravel/framework
react
@vitejs/plugin-react
laravel-vite-plugin
vite
For a Searchbar component I make a form with many fields but when I submit it (using form.get) isDirty keep at true if preserveState is set to true. I don't know if I make something wrong with my default values or with the debounce.
form.get
isDirty
preserveState
I saw someone with a similar issue here https://github.com/inertiajs/inertia/discussions/1033 but I don't understand how he solve it.
const allParams = usePage().props.route.query; const currentRouteName = usePage().props.route.name; const form = useForm({ search: allParams.search || '', searchBy: allParams.searchBy ?? searchByOpts[0].key, orderBy: allParams.orderBy || 'DESC' }); const [debounceTimeout, setDebounceTimeout] = useState(null); useEffect(() => { console.log('isDirty', form.isDirty) if(form.isDirty) { console.log(form.data); // Clear the previous debounced function if (debounceTimeout) clearTimeout(debounceTimeout); // Create a new debounced function setDebounceTimeout(setTimeout(() => { form.get(route(currentRouteName), { preserveScroll: true, preserveState: true }); }, 200)); } }, [form.isDirty]);
Versions:
@inertiajs/react
version: 1.0.15laravel/framework
version : 10.46.0react
version : 18.2.0@vitejs/plugin-react
version : 4.2.1laravel-vite-plugin
version : 1.0.2vite
version : 5.1.6Describe the problem:
For a Searchbar component I make a form with many fields but when I submit it (using
form.get
)isDirty
keep at true ifpreserveState
is set to true. I don't know if I make something wrong with my default values or with the debounce.I saw someone with a similar issue here https://github.com/inertiajs/inertia/discussions/1033 but I don't understand how he solve it.
Code