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

How to implement collection function using react

coldplay.xixi
Release: 2020-11-17 13:49:22
Original
3124 people have browsed it

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>
 
     </>
    )}
Copy after login

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>
     </>
    )}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template