reactjs - 为什么 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)
解决方案
只需要改变
return <Slide direction="up" ref={ref} {...props} />
至
<Slide ref={ref} {...(props as SlideProps)} />
推荐阅读
- windows - Active Directory 组策略在一夜之间自动删除
- python - 更新所有包后 Python DLL 加载失败
- python - 如何在代码中使用 python 覆盖率
- mysql - Mysql查询 - 查找不在多个范围内的总和(常绿)
- context-free-grammar - 上下文无关语法,数字范围
- java - 是否可以使用 JpaRepository 在 Spring Data JPA 中使用“TRUNCATE”?还是比标准 deleteAll() 更有效的方法?
- c++ - 将 gsl c++ 程序与英特尔 MKL 链接
- tcl - 将文件名从按钮重新定位到条目并将文件名用作全局变量
- python - 我不知道为什么,但这段代码有时可以工作,有时会抛出错误任何想法?:
- php - date_diff 的 php 问题