繁体   English   中英

不能重复jsx值道具中的十六进制html实体

[英]can't repeat an hexadecimal html entity in react jsx value props

所以我的问题是为什么这个工作并显示点:

<Field label="Password" value="&#x2022;&#x2022;&#x2022;&#x2022;&#x2022;" type="password" />

以上只显示普通的六进制代码!

<Field label="Password" value={`${'&#x2022;'.repeat(10)}`} type="password" />

我的Field组件:

function renderValueByType(value: string, type: string) {
  switch (type) {
    case 'phone':
      return phoneFormatter(value);

    default:
      return value;
  }
}

/**
 * 
 * @param {*} param0 
 */
const Field = ({ label, value, type, className }: PropTypes) => (
  <div className={className}>
    <span className="Field__label">{label}</span>
    <span className="Field__content">{renderValueByType(value, type)}</span>
  </div>
);

如果将静态字符串设置为prop,它将按原样呈现。

如果将变量设置为prop,则将对其进行清理。

这里你最好的选择是将十六进制字符代码转换为字符串,然后将其传递给组件(使用String.fromCharCode() ):

<Field
   label="Password"
   value={String.fromCharCode("0x2022").repeat(10)}
   type="password"
/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM