无法在react jsx value props中重复十六进制html实体

JSK*_*JSK 5 html javascript jsx reactjs flowtype

所以我的问题是为什么这样做并显示点:

<Field label="Password" value="&#x2022;&#x2022;&#x2022;&#x2022;&#x2022;" type="password" />
Run Code Online (Sandbox Code Playgroud)

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

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

我的字段组件:

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>
);
Run Code Online (Sandbox Code Playgroud)

klu*_*gjo 5

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

如果您将变量设置为道具,它将被清理。

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

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