Home  >  Article  >  Web Front-end  >  How to implement collection function using react

How to implement collection function using react

coldplay.xixi
coldplay.xixiOriginal
2020-11-17 13:49:223046browse

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 implement collection function using react

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 &#39;react&#39;
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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn