代码之家  ›  专栏  ›  技术社区  ›  StackUnderFlow

如何连接道具?

  •  1
  • StackUnderFlow  · 技术社区  · 6 年前

      <Pricing
        title="Standard"
        description={<span>"$"</span> + "25"}
        button="Buy Now for $25" 
        amount={2500}
      />
    
    1 回复  |  直到 6 年前
        1
  •  2
  •   Estus Flask    6 年前

    <span>"$"</span> 导致反应组分将被串化 [object Object] 当与字符串连接时。

    鉴于此 Pricing 渲染 description 支柱组件

    {prop.description}
    

    描述 prop可以提供任何有效的JSX表达式。例如,数组:

      <Pricing
        title="Standard"
        description={[<span>"$"</span>, "25"]}
        button="Buy Now for $25" 
        amount={2500}
      />
    

    或者 React.Fragment

      <Pricing
        title="Standard"
        description={<><span>"$"</span>25</>}
        button="Buy Now for $25" 
        amount={2500}
      />