Home >Web Front-end >JS Tutorial >How to implement collection function using react
How to use react to implement the collection function: click and collect by setting the inverse iconStatus, the code is [const [icoStatus, setIcoStatus] = useState(true)].
How to use react to implement the collection function:
1. Click to collect by setting the iconStatus inversion, The function of canceling collection
import React,{useState} from 'react' function Model(){ const [icoStatus, setIcoStatus] = useState(true) //点击收藏按钮 const iconSouCangData = (event, props) => { setIcoStatus(!icoStatus) } return( <> <span className={icoStatus? " icon-soucang2 soucang-color" : "icon-soucang2"} onClick={(e) => icoStatusData(e,props)}></span> </> )}
2. The following is for collection of circular lists. Cancel collection
import React,{useState} from 'react' function Model(){ const [icoStatus, setIcoStatus] = useState(true) //点击收藏按钮 const iconSouCangData = (event, props) => { setIcoStatus(!icoStatus) } return( <> <span className={iconSouCang ? "opts-icon icon-soucang2 soucang-color" : "icon-hide"} onClick={(e) => iconSouCangData(e,props)}></span> <span className={iconSouCang ? "icon-hide" : "opts-icon icon-soucang"} onClick={(e) => iconSouCangData(e,props)}></span> </> )}
Related free learning recommendations: JavaScript (video )
The above is the detailed content of How to implement collection function using react. For more information, please follow other related articles on the PHP Chinese website!