嘿,伙計們正在使用#hashtags 和@mentions 處理博客內容,如果這些單詞有@mention 或#tags 用錨標簽包裝它們,我想檢查字串中的所有單詞,所以如果我有類似“你好@看門狗是你與@example 和#trends #football"
所以我想換成@watchdog @exmaple #exmaple之類的東西
我正在使用反應 js
export const text = (text) =>{
const [linktext,setLinkText] = useState('')
useEffect(()=>{
},[])
return (
<div>{text}</div>
)
}
uj5u.com熱心網友回復:
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>
)
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/441521.html
標籤:javascript html 节点.js 反应 网络
