@modular-forms/solid
Version:
The modular and type-safe form library for SolidJS
22 lines (21 loc) • 658 B
JavaScript
import { untrack } from 'solid-js';
/**
* Sets the response of the form.
*
* @param form The form of the response.
* @param response The response object.
* @param options The response options.
*/
export function setResponse(form, response, { duration } = {}) {
// Set new response
form.internal.response.set(response);
// If necessary, remove new response after specified duration if response has
// not been changed in meantime
if (duration) {
setTimeout(() => {
if (untrack(form.internal.response.get) === response) {
form.internal.response.set({});
}
}, duration);
}
}