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

使用Styled Component遇报错:Expected an assignment or function call and instead saw an expression

问题解决:Styled Component三元运算符报错「Expected an assignment or function call and instead saw an expression」

你写的箭头函数用了大括号包裹逻辑,但没有显式返回结果,导致函数没有返回值,触发了这个错误。

两种修复方式:

  • 去掉大括号,利用箭头函数的隐式返回特性:
    opacity: ${({ isOpen }) => isOpen ? '100%' : '0'};
    
  • 保留大括号的话,必须添加return语句:
    opacity: ${({ isOpen }) => { return isOpen ? '100%' : '0' }};
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 23:50:31