Skip to content
Discussion options

You must be logged in to vote

@present-g @bluebill1049

You can create a custom hook by using useForm to apply trimming.

For example:

// useCustomForm.ts

export interface UseCustomFormProps extends UseFormProps {
   trim?: boolean;
}

export const useCustomForm = ({ trim, ...props }: UseCustomFormProps) => {
   const methods = useForm(props);

  const customRegister = (name: string, registerOptions?: RegisterOptions) => {
      const field = method.register(name, registerOptions);
      
     const customOnChange: ChangeHandler = async (event) => {
        const target = event.target;

        if (trim && typeof target.value === 'string' && target.value) {
            target.value = target.value.trim();
        }

   …

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
2 replies
@present-g
Comment options

@bluebill1049
Comment options

Comment options

You must be logged in to vote
3 replies
@bluebill1049
Comment options

@jordan-rigo
Comment options

@volpi-indagare
Comment options

Answer selected by bluebill1049
Comment options

You must be logged in to vote
1 reply
@volpi-indagare
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
6 participants