All files / src Select.tsx

100% Statements 10/10
75% Branches 9/12
100% Functions 2/2
100% Lines 10/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34                                9x 2x 2x 2x 1x 1x 1x 1x           2x     9x  
import React, { FC, PropsWithChildren, useEffect, memo } from 'react';
import { useStore } from './store';
 
export interface SelectProps extends React.InputHTMLAttributes<HTMLSelectElement> {
  keyname?: string;
  /**
   * Used to define the name of form controls
   * @deprecated use `name`
   */
  rename?: string;
  /** Can be shown or hidden with controls */
  visible?: boolean;
  /** "index" refers to the use of indexes to control the order of controls, which can provide more flexible API encapsulation. */
  index?: number;
}
 
export const Select: FC<PropsWithChildren<SelectProps>> = memo((props) => {
  const { fields = {}, dispatch } = useStore();
  const { rename, keyname, visible = true, ...elmProps } = props;
  useEffect(() => {
    Eif (keyname || props.name) {
      const key = (keyname || props.name) as string;
      delete fields[key];
      dispatch({
        fields: { ...fields, [key]: visible ? <select {...elmProps} name={rename || props.name} /> : null },
      });
    }
  }, [props]);
 
  return null;
});
 
Select.displayName = 'Login.Select';