The error "Maximum call stack size exceeded" is usually caused by an infinite loop or a function that calls itself too many times. In this case, it seems that the issue is caused by the slug ref being used in both the newCatForm and editCatForm objects.
To fix this, you can create a separate slugEdit ref for the editCatForm object and use it instead of the slug ref.
Here's an example of how you can modify the code:
//Create
const newCatForm = useForm({
name: '',
slug: '',
parent_id: '',
});
let isNewCatOpen = ref(false);
const submitMakeNewCat = () => {
newCatForm.post(route('admin.categories.store'), {
onFinish: () => {
newCatForm.name = '';
newCatForm.slug = '';
newCatForm.parent_id = '';
},
});
isNewCatOpen.value = false;
}
//Update
const slugEdit = ref('');
const editCatForm = useForm({
name: '',
slug: slugEdit,
parent_id: '',
});
let isEditCatOpen = ref(false);
const submitEditCat = (id) => {
editCatForm.put(route('admin.categories.update', id), {
onFinish: () => {
editCatForm.name = '';
editCatForm.slug = '';
editCatForm.parent_id = '';
},
});
isEditCatOpen.value = false;
}
// Checking slug
watch(slug, throttle((newSlug) => {
Inertia.visit(route('admin.categories.index'), {
method: 'post',
data: {slugForCheck: newSlug},
only: ['isSlugExisted'],
preserveState: true,
preserveScroll: true,
});
}, 300));
watch(slugEdit, throttle((newSlug) => {
Inertia.visit(route('admin.categories.index'), {
method: 'post',
data: {slugForCheck: newSlug},
only: ['isSlugExisted'],
preserveState: true,
preserveScroll: true,
});
}, 300));
By creating a separate slugEdit ref for the editCatForm object, you can avoid the infinite loop caused by the slug ref being used in both objects.