[英]can't repeat an hexadecimal html entity in react jsx value props
所以我的問題是為什么這個工作並顯示點:
<Field label="Password" value="•••••" type="password" />
以上只顯示普通的六進制代碼!
<Field label="Password" value={`${'•'.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.