【问题标题】:React Material UI Button color attribute ternary operatorReact Material UI Button 颜色属性 三元运算符
【发布时间】:2023-03-25 04:30:01
【问题描述】:

我正在尝试根据加载程序有条件地渲染按钮的颜色。不确定我在语法上做错了什么。

<Button type="submit" color={{ loader ? : "primary" : "disabled"}}>
  Join the Waitlist!
</Button>

【问题讨论】:

    标签: reactjs conditional-operator


    【解决方案1】:

    color 正在等待 string 而不是 object

    color={loader ? "primary" : "disabled"}
    

    在此处查看示例: https://material-ui.com/components/buttons/#button

    【讨论】:

    • "disabled" 值对我不起作用(使用 TypeScript),我有一个“没有重载匹配此调用”错误。我解决了这个问题:“color={loader ?”primary”: undefined}”
    猜你喜欢
    • 1970-01-01
    • 2020-11-25
    • 2019-10-03
    • 2021-03-16
    • 2023-03-10
    • 2018-03-26
    • 2021-01-28
    • 1970-01-01
    • 2020-08-17
    相关资源
    最近更新 更多