【问题标题】:'prop' is missing in props validation?道具验证中缺少“道具”?
【发布时间】: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


    【解决方案1】:

    这是我想象的 eslint 的错误?但这有帮助吗?

    ({ direction, animatingOut, children }: Props, ref) => ( // <-- error here
    

    【讨论】:

    • 我有这个确切的问题,这对我的情况似乎没有帮助。
    • 需要更多详细信息才能在此处有所帮助。你有什么确切的错误,在哪一行?你周围的代码是什么样的?
    猜你喜欢
    • 2018-08-01
    • 2020-05-19
    • 1970-01-01
    • 1970-01-01
    • 2017-09-26
    • 1970-01-01
    • 1970-01-01
    • 2019-11-18
    • 2020-10-29
    相关资源
    最近更新 更多