【发布时间】:2021-09-04 14:16:01
【问题描述】:
我是 react 的 forwardRef 的新手,我需要帮助。我在FadeContents 的道具上遇到错误,其中指出例如道具验证中缺少“方向”。这个问题有方法解决吗?我觉得我必须在某个地方定义道具才能在 div 元素中使用它们,我似乎无法理解在哪里?蒂亚!
// @flow
import React, { forwardRef } from "react"
import type { Node } from "react"
type Props = {
direction: 'left' | 'right',
animatingOut: boolean,
children: Node,
}
const FadeContents = forwardRef<Props, HTMLDivElement>(
({ direction, animatingOut, children }, ref) => ( // <-- error here
<div
aria-hidden={animatingOut}
animatingOut={animatingOut}
direction={direction}
ref={ref}
>
{children}
</div>
)
)
FadeContents.displayName = 'FadeContents'
export default FadeContents
【问题讨论】:
标签: javascript reactjs eslint flowtype