正在尝试处理React/TS应用中某个组件的某些鼠标事件。不确定将鼠标事件放在何处或如何将其/已处理的事件从子道具向上传递回父道具。
这是代码:
const [isMouseOver, setIsMouseOver] = useState(false)
<ContentRightHandSide
onMouseEnter={() => setIsMouseOver(true)}
onMouseLeave={() => setIsMouseOver(false)}
>
[...]
</ContentRightHandSide>
这是ContentRightHandSide组件的代码
type ContentRightHandSideProps = {
children?: ReactNode;
};
export function ContentRightHandSide({
children,
offset,
}: ContentRightHandSideProps) {
return (
<div>
{children}
</div>
);
}
这是错误:
(property) onMouseEnter: () => any
Type '{ children: Element[]; offset: number; onMouseEnter: () => any; onMouseLeave: () => any; }'
is not assignable to type 'IntrinsicAttributes & ContentRightHandSideProps'.
Property 'onMouseEnter' does not exist on type 'IntrinsicAttributes & ContentRightHandSideProps'
我将非常感谢任何帮助提供,谢谢!
1条答案
按热度按时间izj3ouym1#
无法在自定义组件上调用事件,除非在属性中定义了该事件