我想插入一个html标记以自定义单个字母。问题在于结果是[object object]。怎么了
const getAndChangeCustomI = (content) => {
let iIndex = content.indexOf("i");
let insert = [];
insert.push(<span className="customLetterI" > I</span>)
content.slice(0, iIndex) + content.slice(iIndex + 1);
if (iIndex > 0) {
return content.substring(0, iIndex) + insert[0] + content.substr(iIndex);
}
return insert + content;
}
您尝试将字符串与节点数组连接在一起。您应该将返回值构造为节点,以保留跨度:
return <>{content.substring(0, iIndex)}{insert[0]}{content.substr(iIndex)}</>;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句