[英]Wrap words in a string with strong tags given a list of words once and in order
[英]How to wrap words with anchor tags in react if string contains certain symbols
嘿伙计们正在使用#hashtags 和@mentions 处理博客内容,我想检查一个字符串中的所有单词,如果这些单词有@mention 或#tags 用锚标记包裹它们,所以incase 我有类似“hello @看门狗是你@example 和#trends #football"
所以我想包装成类似@watchdog @exmaple #exmaple的东西
我正在使用反应 js
export const text = (text) =>{
const [linktext,setLinkText] = useState('')
useEffect(()=>{
},[])
return (
<div>{text}</div>
)
}
export const text = (text) =>{
const [linktext,setLinkText] = useState("hello @watchdog are you with @example and #trends #football")
useEffect(()=>{
},[])
return (
<div>{linktext.split(" ").map(word => (
(word.includes("@") || word.includes("#"))
?
<a>{word} </a>
:
<p>{word}</p>
))}</div>
)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.