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 | 9x 2x 2x 1x 1x 1x 1x 1x 2x 9x | import { FC, PropsWithChildren, useEffect, memo } from 'react'; import { useStore } from './store'; export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> { keyname?: 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 Button: FC<PropsWithChildren<ButtonProps>> = memo((props) => { const { buttons = {}, dispatch } = useStore(); useEffect(() => { const { keyname, visible = true, ...elmProps } = props; Eif (keyname || elmProps.name) { const key = (keyname || elmProps.name) as string; delete buttons[key]; dispatch({ buttons: { ...buttons, [key]: visible ? <button type="submit" {...elmProps} /> : null }, }); } }, [props]); return null; }); Button.displayName = 'Login.Button'; |