javascript - 收到非布尔属性“正在加载”的“假”
问题描述
我已经创建了一个基于Material-UI 的 Button 组件的自定义按钮组件,因此我可以在待处理的操作时覆盖加载圈。然而,React 抱怨如下:
警告:收到false
非布尔属性loading
。如果要将其写入 DOM,请改为传递字符串:loading="false" 或 loading={value.toString()}。
这是我的组件的样子。提前致谢!
import * as React from 'react'
import { ButtonProps } from '@material-ui/core/Button'
import { Button, CircularProgress } from '@material-ui/core'
interface IProps extends ButtonProps {
loading: boolean
}
export const LoadingButton = (props: IProps) => {
const { disabled, loading } = props
return (
<div className='button-container'>
<Button {...props} disabled={disabled == true || loading == true}/>
{loading == true && (
<CircularProgress size={24} className='button-progress' />
)}
</div>
)
}
解决方案
您不应该将自定义道具传递给 Button。
代替
const { disabled, loading } = props
和
const { disabled, loading, ...rest } = props
接着
<Button {...rest} disabled={disabled || loading}/>
推荐阅读
- android - 使用 listview 时如何打开存储在 assets 文件夹中的 pdf 文件?
- vba - VBA - 替换单词表中的文本
- javascript - ReactJS 无法识别
- java - 消息:PrimeFaces Extensions DocumentViewer 中缺少 PDF
- windows-store-apps - Windows 商店支持的语言
- javascript - 在 IBM Cloud Functions / OpenWhisk 中使用 TypeScript 的任何入门工具包或示例?
- c# - 如何将 C# 事件转换为 Delphi
- unix - 需要帮助打印
- c# - OpenPop.net 从附件中获取实际的消息文本
- html - 该部分不适用于通用目的