【问题标题】:React native, <Text> in more than one lineReact native, <Text> 不止一行
【发布时间】:2020-11-10 02:11:47
【问题描述】:

我有这个代码:

<Text style={[fontStyles.transactionTimeText]} testID="timeExpirationMessage">
  Tu cotización será válida hasta las <Moment element={Text} format="YYYY/MM/DD">{expiresDate}</Moment> horas
</Text>

我想让每行更短,如下所示:

<Text style={[fontStyles.transactionTimeText]} testID="timeExpirationMessage">
  Tu cotización será válida hasta las
  <Moment 
    element={Text}
    format="YYYY/MM/DD">{expiresDate}
  </Moment>
  horas
</Text>

但这样一来,{expiresDate} 之前和之后的文本没有空格,如果我尝试在其中放置空格,则会出现 ESLint 错误:

【问题讨论】:

    标签: react-native eslint


    【解决方案1】:

    如果我理解正确,您可以这样做:

    <Text style={[fontStyles.transactionTimeText]} testID="timeExpirationMessage">
      Tu cotización será válida hasta las{' '}
      <Moment element={Text} format="YYYY/MM/DD">
        {expiresDate}
      </Moment>{' '}
      horas
    </Text>
    

    {' '} 负责处理尾随空格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-18
      • 2023-03-21
      • 2019-03-01
      • 2022-12-27
      • 2019-11-05
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多