首页 > 解决方案 > 为什么 Material-UI 不允许在此处进行自定义转换?

问题描述

我正在使用 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)

标签: reactjstypescriptmaterial-ui

解决方案


只需要改变

return <Slide direction="up" ref={ref} {...props} />

<Slide ref={ref} {...(props as SlideProps)} />


推荐阅读