【问题标题】:Why is Material-UI not allowing for custom transition here?为什么 Material-UI 不允许在此处进行自定义转换?
【发布时间】:2021-11-06 18:40:53
【问题描述】:

我正在使用 Material-UI v4 在“Snackbar”上创建自定义过渡。默认情况下,转换工作,但是当我尝试添加自己的转换时,我遇到了类型问题。

过渡代码:

<SnackbarProvider
          maxSnack={3}
          TransitionComponent={React.forwardRef(function Transition(
            props,
            ref
          ) {
            return <Slide direction="up" ref={ref} {...props} />
          })}
        >

将鼠标悬停在幻灯片上时显示错误:

Types of property 'children' are incompatible.
    Type 'ReactNode' is not assignable to type 'ReactElement<any, any> | undefined'.
      Type 'null' is not assignable to type 'ReactElement<any, any> | undefined'.ts(2322)

【问题讨论】:

    标签: reactjs typescript material-ui


    【解决方案1】:

    只需要改变

    return &lt;Slide direction="up" ref={ref} {...props} /&gt;

    &lt;Slide ref={ref} {...(props as SlideProps)} /&gt;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-02
      • 2020-05-29
      • 1970-01-01
      • 2013-04-23
      • 1970-01-01
      • 2014-04-18
      • 1970-01-01
      相关资源
      最近更新 更多