You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用MaterialUI TableCell组件报错:capitalize期望字符串参数求解决

修复MUI TableCell的"capitalize(string) expects a string argument"错误

问题根源

你给TableCell的align属性传入了null,而MUI内部处理该属性时会调用capitalize函数,这个函数要求参数必须是字符串类型,null不符合要求,因此抛出错误。

修复方案

将align属性的null替换为合法的字符串取值,比如MUI TableCell支持的'left'、'inherit'(默认值)等。

修改后的代码示例:

<TableCell
  style={{
    color: "white",
    fontFamily: "Montserrat",
    fontWeight: "700",
  }}
  key={head}
  align={head === "Coin" ? "left" : "right"}
>
  {head}
</TableCell>

或者使用默认的继承值:

<TableCell
  style={{
    color: "white",
    fontFamily: "Montserrat",
    fontWeight: "700",
  }}
  key={head}
  align={head === "Coin" ? "inherit" : "right"}
>
  {head}
</TableCell>

补充说明

TableCell的align属性仅接受以下字符串值:'left'、'right'、'center'、'justify'、'inherit',不能传入null、undefined或其他非字符串类型的值。

内容的提问来源于stack exchange,提问作者Cookie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 07:52:03