RESOLVED - Understanding how hooks work

Hi Yisrael,

my goal and understand how they work. Let’s take an example:

NOW MY CODE

function hideImput() {
setTimeout(() => {
$w(‘#textSaveForm’).hide(‘FadeOut’);
}, 1500);
}

export function SaveData_click() {
let toInsert = {
“dataEvento”: $w(" #ImptData “).value,
“tipoEvento”: $w(” #ImptEvent “).value,
“nomeEventoOErimonia”: $w(” #ImputName “).value,
“code”: $w(” #ImptCode “).value,
“utenteRedirect”: $w(” #ImpuUser “).value,
“redirect”: $w(” #ImputUrl “).value
};
wixData.insert(“RedirectCerimonie”, toInsert)
.then( (results) => {
$w(” #textSaveForm “).text = “Form salvato con successo”;
$w(” #textSaveForm ").show();
hideImput()
})
.catch( (err) => {
let errorMsg = err;
console.log(errorMsg);
});
}

it is possible to change it with

export function RedirectCerimonie_afterInsert(item, context) {
setTimeout(() => {
$w(‘#textSaveForm’).hide(‘FadeOut’);
}, 1500);
}

export function SaveData_click() {
let toInsert = {
“dataEvento”: $w(" #ImptData “).value,
“tipoEvento”: $w(” #ImptEvent “).value,
“nomeEventoOErimonia”: $w(” #ImputName “).value,
“code”: $w(” #ImptCode “).value,
“utenteRedirect”: $w(” #ImpuUser “).value,
“redirect”: $w(” #ImputUrl “).value
};
wixData.insert(“RedirectCerimonie”, toInsert)
.then( (results) => {
$w(” #textSaveForm “).text = “Form salvato con successo”;
$w(” #textSaveForm ").show();
hideImput()
})
.catch( (err) => {
let errorMsg = err;
console.log(errorMsg);
});
}

I can not figure out what the difference is, so I hook up the hooks.
In my opinion they must be very useful to shorten the code but I do not understand how and when to use them.

Thank you