From 8b57732722ba9b4ddf76b15d373f8006b50aa4a8 Mon Sep 17 00:00:00 2001 From: Madeorsk Date: Mon, 23 Sep 2024 18:45:41 +0200 Subject: [PATCH] Add submit function dependencies to useFormSubmit hook. --- package.json | 2 +- src/Utils.tsx | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index d0ea7dc..5eb600f 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "version": "1.3.0", + "version": "1.3.1", "name": "@kernelui/core", "description": "Kernel UI Core.", "scripts": { diff --git a/src/Utils.tsx b/src/Utils.tsx index 48dd5e7..0eec34a 100644 --- a/src/Utils.tsx +++ b/src/Utils.tsx @@ -1,4 +1,4 @@ -import React, {FormEvent, useCallback, useEffect, useRef} from "react"; +import React, {DependencyList, FormEvent, useCallback, useEffect, useRef} from "react"; export type Modify = Omit & R; @@ -54,8 +54,9 @@ export function usePreviousValue(currentValue: T): T /** * Create a callback for a form submit function that fully overrides default form behavior. * @param submitFunction The function to call on form submit. + * @param dependencies Submit function dependencies. */ -export function useFormSubmit(submitFunction: () => void): React.FormEventHandler +export function useFormSubmit(submitFunction: () => void, dependencies: DependencyList = []): React.FormEventHandler { // Use a memoized callback. return useCallback((event: React.FormEvent) => { @@ -63,5 +64,5 @@ export function useFormSubmit(submitFunction: () => void): React.FormEventHandle event.preventDefault(); submitFunction(); return false; - }, [submitFunction]); + }, [submitFunction, ...dependencies]); }