-
拜读代码时看到了这样的写法。 type NativeButtonProps = DetailedHTMLProps<
ButtonHTMLAttributes<HTMLButtonElement>,
HTMLButtonElement
>
export type ButtonProps = {
color?: 'default' | 'primary' | 'success' | 'warning' | 'danger'
// ... 省略
children?: ReactNode
} & Pick<
NativeButtonProps,
'onMouseDown' | 'onMouseUp' | 'onTouchStart' | 'onTouchEnd' | 'id'
> &
NativeProps<
| '--text-color'
// ... 省略
| '--border-color'
> 想请教一下为什么选择使用使用 Pick 将部分原生 button 的部分属性暴露给外界更改,而不是将自定义的属性提取出来后,将剩余所有的原生属性解构赋值给 button。 谢谢! |
Beta Was this translation helpful? Give feedback.
Answered by
zombieJ
Apr 9, 2025
Replies: 1 comment 1 reply
-
API 暴露出去很难收回来,二次封装的组件不一定方法和原生是一致的。比如说各种输入型组件的 |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
lilmonix2
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
API 暴露出去很难收回来,二次封装的组件不一定方法和原生是一致的。比如说各种输入型组件的
onChange
事件,对应到原生是e.target.value
获取值,但是封装的组件不一定有这个 event 对象。某天另一个组件决定添加onInput
然后发现已经被原生暴露出去了,就会导致这个 API 实际上废掉了(原因相同封装组件没有 event 对象)。