Piplup
@piplup/rhf-adaptersmui-chips-inputHooks

useMuiChipsInputAdapter

Returns adapter props for building custom mui-chips-input integrations with React Hook Form.

Import

import { useMuiChipsInputAdapter } from "@piplup/rhf-adapters/mui-chips-input";

Usage

import * as React from 'react';import { type Transform } from '@piplup/rhf-core';import { MuiChipsInput } from 'mui-chips-input';import { type FieldPath, type FieldValues } from 'react-hook-form';import {  type UseMuiChipsInputAdapterProps,  useMuiChipsInputAdapter,} from './adapter';type MuiChipsInputProps = React.ComponentProps<typeof MuiChipsInput>;export interface MuiChipsInputElementProps<  TTransformedValue extends string[],  TFieldValues extends FieldValues = FieldValues,  TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,> extends Omit<      MuiChipsInputProps,      'checked' | 'defaultChecked' | 'defaultValue' | 'name' | 'style' | 'value'    >,    Omit<      UseMuiChipsInputAdapterProps<TTransformedValue, TFieldValues, TName>,      'composeHelperText' | 'onBlur' | 'onChange' | 'transform'    > {  /**   * Transformation functions for the field's input and output values.   */  transform?: Transform<    MuiChipsInputProps['onChange'],    TTransformedValue,    TFieldValues,    TName  >;}function MuiChipsInputComponent<  TTransformedValue extends string[],  TFieldValues extends FieldValues = FieldValues,  TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,>(  props: MuiChipsInputElementProps<TTransformedValue, TFieldValues, TName>,  ref?: MuiChipsInputProps['ref'],): React.ReactElement {  const {    className,    control,    defaultValue,    disabled,    disableOnError,    disableOnIsSubmitting,    error,    errorParser,    helperText,    inputRef,    messages,    name,    onBlur,    onChange,    required,    rules,    shouldUnregister,    style,    title,    transform,    ...rest  } = props;  const adapter = useMuiChipsInputAdapter(    {      className,      composeHelperText: true,      control,      defaultValue,      disabled,      disableOnError,      disableOnIsSubmitting,      error,      errorParser,      helperText,      inputRef,      messages,      name,      onBlur,      onChange,      required,      rules,      shouldUnregister,      style,      title,      transform,    },    ref,  );  return <MuiChipsInput {...(rest as MuiChipsInputProps)} {...adapter} />;}export const MuiChipsInputElement = React.forwardRef(  MuiChipsInputComponent,) as typeof MuiChipsInputComponent & { displayName?: string };if (process.env.NODE_ENV !== 'production') {  MuiChipsInputElement.displayName = 'MuiChipsInputElement';}

Props

Prop

Type

Return value

Prop

Type

Notes

  • Use this hook for custom chip inputs that still need react-hoook-form controlled value handling.
  • It builds on useControllerAdapter.

On this page