Add submit function dependencies to useFormSubmit hook.
This commit is contained in:
parent
2350d50b3e
commit
8b57732722
2 changed files with 5 additions and 4 deletions
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"version": "1.3.0",
|
||||
"version": "1.3.1",
|
||||
"name": "@kernelui/core",
|
||||
"description": "Kernel UI Core.",
|
||||
"scripts": {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import React, {FormEvent, useCallback, useEffect, useRef} from "react";
|
||||
import React, {DependencyList, FormEvent, useCallback, useEffect, useRef} from "react";
|
||||
|
||||
export type Modify<T, R> = Omit<T, keyof R> & R;
|
||||
|
||||
|
@ -54,8 +54,9 @@ export function usePreviousValue<T>(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<HTMLFormElement>
|
||||
export function useFormSubmit(submitFunction: () => void, dependencies: DependencyList = []): React.FormEventHandler<HTMLFormElement>
|
||||
{
|
||||
// Use a memoized callback.
|
||||
return useCallback((event: React.FormEvent<HTMLFormElement>) => {
|
||||
|
@ -63,5 +64,5 @@ export function useFormSubmit(submitFunction: () => void): React.FormEventHandle
|
|||
event.preventDefault();
|
||||
submitFunction();
|
||||
return false;
|
||||
}, [submitFunction]);
|
||||
}, [submitFunction, ...dependencies]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue