Best Python code snippet using hypothesis
Sgpa_calculator.js
Source:Sgpa_calculator.js  
1import React from 'react'2import { Redirect } from 'react-router-dom';3import './Sgpa_calculator.css'4  class Sgpacalculator extends React.Component {5    constructor(props) {6    super(props);7      this.state = {8       Title:'',9       print:false,10        sub1:'',11        sub2:'',12        sub3:'',13        sub4:'',14        sub5:'',15        sub6:'',16        sub7:'',17        sub8:'',18        sub9:'',19        m1:'',20        m2:'',21        m3:'',22        m4:'',23        m5:'',24        m6:'',25        m7:'',26        m8:'',27        m9:'',28        c1:'0',29        c2:'0',30        c3:'0',31        c4:'0',32        c5:'0',33        c6:'0',34        c7:'0',35        c8:'0',36        c9:'0',37        x1:0,38        x2:0,39        x3:0,40        x4:0,41        x5:0,42        x6:0,43        x7:0,44        x8:0,45        x9:0,46        t2:''47      };48    }49  handlenum1=(event)=>{50    (event.target.value>100 || event.target.value<0) ? alert("You can only insert value in range of 0 to 100") : console.log('hello');51        (event.target.value>100 || event.target.value<0) ? event.target.value=0 : console.log('hello');52     this.setState({53       m1:event.target.value,54       print:false,55     });56 }57 handleChange2=(event)=>{58   (event.target.value>100 || event.target.value<0) ? alert("You can only insert value in range of 0 to 100") : console.log('hello');59        (event.target.value>100 || event.target.value<0) ? event.target.value=0 : console.log('hello');60  this.setState({61    m2:event.target.value,62    print:false,63  });64}65handleChange3=(event)=>{66  (event.target.value>100 || event.target.value<0) ? alert("You can only insert value in range of 0 to 100") : console.log('hello');67        (event.target.value>100 || event.target.value<0) ? event.target.value=0 : console.log('hello');68  this.setState({69    m3:event.target.value,70    print:false,71  });72}73handleChange4=(event)=>{74  (event.target.value>100 || event.target.value<0) ? alert("You can only insert value in range of 0 to 100") : console.log('hello');75        (event.target.value>100 || event.target.value<0) ? event.target.value=0 : console.log('hello');76  this.setState({77    m4:event.target.value,78    print:false,79  });80}81handleChange5=(event)=>{82  (event.target.value>100 || event.target.value<0) ? alert("You can only insert value in range of 0 to 100") : console.log('hello');83        (event.target.value>100 || event.target.value<0) ? event.target.value=0 : console.log('hello');84  this.setState({85    m5:event.target.value,86    print:false,87  });88}89handleChange6=(event)=>{90  (event.target.value>100 || event.target.value<0) ? alert("You can only insert value in range of 0 to 100") : console.log('hello');91        (event.target.value>100 || event.target.value<0) ? event.target.value=0 : console.log('hello');92  this.setState({93    m6:event.target.value,94    print:false,95  });96}97handleChange7=(event)=>{98  (event.target.value>100 || event.target.value<0) ? alert("You can only insert value in range of 0 to 100") : console.log('hello');99        (event.target.value>100 || event.target.value<0) ? event.target.value=0 : console.log('hello');100  this.setState({101    m7:event.target.value,102    print:false,103  });104}105handleChange8=(event)=>{106  (event.target.value>100 || event.target.value<0) ? alert("You can only insert value in range of 0 to 100") : console.log('hello');107        (event.target.value>100 || event.target.value<0) ? event.target.value=0 : console.log('hello');108  this.setState({109    m8:event.target.value,110    print:false,111  });112}113handleChange9=(event)=>{114  (event.target.value>100 || event.target.value<0) ? alert("You can only insert value in range of 0 to 100") : console.log('hello');115        (event.target.value>100 || event.target.value<0) ? event.target.value=0 : console.log('hello');116  this.setState({117    m9:event.target.value,118    print:false,119  });120}121exe=(event)=>{122  event.preventDefault();123  if(this.state.m1==='')124  {125    (this.setState({x1:0}))126  }127  else128  {129    ((Number(this.state.m1)===100)? this.setState({x1:10}):this.setState({x1:Number(Math.floor(this.state.m1/10))+1}));130  }131  if(this.state.m2==='')132  {133    (this.setState({x2:0}))134  }135  else136  {137    ((Number(this.state.m2)===100)? this.setState({x2:10}):this.setState({x2:Number(Math.floor(this.state.m2/10))+1}));138  }139  if(this.state.m3==='')140  {141    (this.setState({x3:0}))142  }143  else144  {145    ((Number(this.state.m3)===100)? this.setState({x3:10}):this.setState({x3:Number(Math.floor(this.state.m3/10))+1}));146  }147  if(this.state.m4==='')148  {149    (this.setState({x4:0}))150  }151  else152  {153    ((Number(this.state.m4)===100)? this.setState({x4:10}):this.setState({x4:Number(Math.floor(this.state.m4/10))+1}));154  }155  if(this.state.m5==='')156  {157    (this.setState({x5:0}))158  }159  else160  {161    ((Number(this.state.m5)===100)? this.setState({x5:10}):this.setState({x5:Number(Math.floor(this.state.m5/10))+1}));162  }163  if(this.state.m6==='')164  {165    (this.setState({x6:0}))166  }167  else168  {169    ((Number(this.state.m6)===100)? this.setState({x6:10}):this.setState({x6:Number(Math.floor(this.state.m6/10))+1}));170  }171  if(this.state.m7==='')172  {173    (this.setState({x7:0}))174  }175  else176  {177    ((Number(this.state.m7)===100)? this.setState({x7:10}):this.setState({x7:Number(Math.floor(this.state.m7/10))+1}));178  }179  if(this.state.m8==='')180  {181    (this.setState({x8:0}))182  }183  else184  {185    ((Number(this.state.m8)===100)? this.setState({x8:10}):this.setState({x8:Number(Math.floor(this.state.m8/10))+1}));186  }187  if(this.state.m9==='')188  {189    (this.setState({x9:0}))190  }191  else192  {193    ((Number(this.state.m9)===100)? this.setState({x9:10}):this.setState({x9:Number(Math.floor(this.state.m9/10))+1}));194  }195  196  // (this.state.m2==='')?(this.setState({x2:0})):((this.state.m2==='100')? this.setState({x2:10}):this.setState({x2:Number(Math.floor(this.state.m2/10))+1}))197  // (this.state.m3==='')?(this.setState({x3:0})):((this.state.m3==='100')? this.setState({x3:10}):this.setState({x3:Number(Math.floor(this.state.m3/10))+1}))198  // (this.state.m4==='')?(this.setState({x4:0})):((this.state.m4==='100')? this.setState({x4:10}):this.setState({x4:Number(Math.floor(this.state.m4/10))+1}))199  // (this.state.m5==='')?(this.setState({x5:0})):((this.state.m5==='100')? this.setState({x5:10}):this.setState({x5:Number(Math.floor(this.state.m5/10))+1}))200  // (this.state.m6==='')?(this.setState({x6:0})):((this.state.m6==='100')? this.setState({x6:10}):this.setState({x6:Number(Math.floor(this.state.m6/10))+1}))201  // (this.state.m7==='')?(this.setState({x7:0})):((this.state.m7==='100')? this.setState({x7:10}):this.setState({x7:Number(Math.floor(this.state.m7/10))+1}))202  // (this.state.m8==='')?(this.setState({x8:0})):((this.state.m8==='100')? this.setState({x8:10}):this.setState({x8:Number(Math.floor(this.state.m8/10))+1}))203  // (this.state.m9==='')?(this.setState({x9:0})):((this.state.m9==='100')? this.setState({x9:10}):this.setState({x9:Number(Math.floor(this.state.m9/10))+1}))204  this.setState({205        t2:(Number(this.state.c1)+Number(this.state.c2)+Number(this.state.c3)+Number(this.state.c4)+Number(this.state.c5)+Number(this.state.c6)+Number(this.state.c7)+Number(this.state.c8)+Number(this.state.c9))206  });207  this.setState({ print:true});208}209  render(){210    if(this.props.brch==='' || this.props.sem===''){211      console.log('return');212      return <Redirect to="/home" />213    }214    console.log(this.props.brch);215    console.log(this.props.sem);216    if (this.props.sem ==='1st & 2nd SEM PHYSICS-CYCLE') {217      if(this.state.Title!=='(2018 SCHEME) PHYSICS GROUP 1ST & 2ND SEM.'){218      this.setState({219                Title:"(2018 SCHEME) PHYSICS GROUP 1ST & 2ND SEM.",220          sub1:"18MAT11/21",221          c1:'4',222          sub2:"18PHY12/22",223          c2:'4',224          sub3:"18ELE13/23",225          c3:'3',226          sub4:"18CIV14/24",227          c4:'3',228          sub5:"18EGDL15/25",229          c5:'3',230          sub6:"18PHYL16/26",231          c6:'1',232          sub7:"18ELEL17/27",233          c7:'1',234          sub8:"18EGH18/28",235          c8:'1'236      });237    }238    }239    else if (this.props.sem === "1st & 2nd SEM CHEMISTRY-CYCLE") {   240      if(this.state.Title!=='(2018 SCHEME) CHEMISTRY GROUP 1ST & 2ND SEM.'){241     this.setState({Title:("(2018 SCHEME) CHEMISTRY GROUP 1ST & 2ND SEM.")})242     this.setState({243      c1:'4',244      c2:'4',245      c3:'3',246      c4:'3',247      c5:'3',248      c6:'1',249      c7:'1',250      c8:'1'251     })252      this.setState({sub1:("18MAT11/21")})253      254      this.setState({sub2:("18CHE12")})255        this.setState({sub3:("18CPS13")})256        this.setState({sub4:("18ELN14")})257        this.setState({sub5:("18ME15")})258        this.setState({sub6:("18CHEL16")})259        this.setState({sub7:("18CPL17")})260        this.setState({sub8:("18EGH18")})261      }262    }263      else if (this.props.brch === "cse") {264        switch (this.props.sem) {265          case '3':266              // console.log(sem);267              if(this.state.Title!=='3rd SEM'){268                this.setState({269                  c1:'3',270                  c2:'4',271                  c3:'3',272                  c4:'3',273                  c5:'3',274                  c6:'3',275                  c7:'2',276                  c8:'2',277                  c9:'1'278                 })279              this.setState({Title:("3rd SEM")})280              this.setState({sub1:("18MAT31")})281            this.setState({sub2:("18CS32")})282            this.setState({sub3:("18CS33")})283            this.setState({sub4:("18CS34")})284            this.setState({sub5:("18CS35")})285            this.setState({sub6:("18CS36")})286            this.setState({sub7:("18CSL37")})287            this.setState({sub8:("18CSL38")})288            this.setState({sub9:("18KVK39/18KAK39/18CPC39")})289              }290           break;291        case '4':292          if(this.state.Title!=='4th SEM'){293            this.setState({294              c1:'3',295              c2:'4',296              c3:'3',297              c4:'3',298              c5:'3',299              c6:'3',300              c7:'2',301              c8:'2',302              c9:'1'303             })304           this.setState({Title:("4th SEM")})305          this.setState({sub1:("18MAT41")})306          this.setState({sub2:("18CS42")})307          this.setState({sub3:("18CS43")})308          this.setState({sub4:("18CS44")})309          this.setState({sub5:("18CS45")})310          this.setState({sub6:("18CS46")})311          this.setState({sub7:("18CSL47")})312          this.setState({sub8:("18CSL48")})313          this.setState({sub9:("18KVK39/18KAK39/18CPC39")})314        }315        break;316        case '5':317          if(this.state.Title!=='5th SEM'){318            this.setState({319              c1:'3',320              c2:'4',321              c3:'4',322              c4:'3',323              c5:'3',324              c6:'3',325              c7:'2',326              c8:'2',327              c9:'1'328            329             })330           this.setState({Title:("5th SEM")})331          this.setState({sub1:("18MAT51")})332          this.setState({sub2:("18CS52")})333          this.setState({sub3:("18CS53")})334          this.setState({sub4:("18CS54")})335          this.setState({sub5:("18CS55")})336          this.setState({sub6:("18CS56")})337          this.setState({sub7:("18CSL57")})338          this.setState({sub8:("18CSL58")})339          this.setState({sub9:("18CIV59")})340          }341          break;342        case '6':343          if(this.state.Title!=='6th SEM'){344            this.setState({345              c1:'4',346              c2:'4',347              c3:'4',348              c4:'3',349              c5:'3',350              c6:'2',351              c7:'2',352              c8:'2'353             })354           this.setState({Title:("6th SEM")})355          this.setState({sub1:("18IS61")})356          this.setState({sub2:("18IS62")})357          this.setState({sub3:("18CS63")})358          this.setState({sub4:("18CS64X")})359          this.setState({sub5:("18CS65X")})360          this.setState({sub6:("18ISL66")})361          this.setState({sub7:("18ISL67")})362          this.setState({sub8:("18CSMP68")})363          }364          break;365        case '7':366          if(this.state.Title!=='7th SEM'){367            this.setState({368              c1:'4',369              c2:'4',370              c3:'3',371              c4:'3',372              c5:'3',373              c6:'2',374              c7:'1'              375             })376           this.setState({Title:("7th SEM")})377          this.setState({sub1:("18CS71")})378          this.setState({sub2:("18CS72")})379          this.setState({sub3:("18CS73X")})380          this.setState({sub4:("18CS74X")})381          this.setState({sub5:("18CS75X")})382          this.setState({sub6:("18CSL76")})383          this.setState({sub7:("18CSP77")})384          }385          break;386        case '8':387          if(this.state.Title!=='8th SEM'){388            this.setState({389              c1:'3',390              c2:'3',391              c3:'8',392              c4:'1',393              c5:'3'394                            395             })396           this.setState({Title:("8th SEM")})397          this.setState({sub1:("18CS81")})398          this.setState({sub2:("18CS82X")})399          this.setState({sub3:("18CSP83")})400          this.setState({sub4:("18CSS84")})401          this.setState({sub5:("18CSI85")})402          }403          break;404        default:405          break;406      }407    }408    else if (this.props.brch === "ece") {409      switch (this.props.sem) {410        case '3':411          if(this.state.Title!=='3rd SEM'){412            this.setState({413              c1:'3',414              c2:'4',415              c3:'3',416              c4:'3',417              c5:'3',418              c6:'3',419              c7:'2',420              c8:'2',421              c9:'1'422             })423           this.setState({Title:("3rd SEM")})424          this.setState({sub1:("18MAT31")})425          this.setState({sub2:("18EC32")})426          this.setState({sub3:("18EC33")})427          this.setState({sub4:("18EC34")})428          this.setState({sub5:("18EC35")})429          this.setState({sub6:("18EC36")})430          this.setState({sub7:("18ECL37")})431          this.setState({sub8:("18ECL38")})432          this.setState({sub9:("18KVK39/18KAK39/18CPC39")})433          }434          break;435        case '4':436          if(this.state.Title!=='4th SEM'){437            this.setState({438              c1:'3',439              c2:'4',440              c3:'3',441              c4:'3',442              c5:'3',443              c6:'3',444              c7:'2',445              c8:'2',446              c9:'1'447             })448           this.setState({Title:("4th SEM")})449          this.setState({sub1:("18MAT41")})450          this.setState({sub2:("18EC42")})451          this.setState({sub3:("18EC43")})452          this.setState({sub4:("18EC44")})453          this.setState({sub5:("18EC45")})454          this.setState({sub6:("18EC46")})455          this.setState({sub7:("18ECL47")})456          this.setState({sub8:("18ECL48")})457          this.setState({sub9:("18KVK39/18KAK39/18CPC39")})}458          break;459        case '5':460          if(this.state.Title!=='5th SEM'){461            this.setState({462              c1:'3',463              c2:'4',464              c3:'4',465              c4:'3',466              c5:'3',467              c6:'3',468              c7:'2',469              c8:'2',470              c9:'1'471            472             })473           this.setState({Title:("5th SEM")})474          this.setState({sub1:("18ES51")})475          this.setState({sub2:("18EC52")})476          this.setState({sub3:("18EC53")})477          this.setState({sub4:("18EC54")})478          this.setState({sub5:("18EC55")})479          this.setState({sub6:("18EC56")})480          this.setState({sub7:("18ECL57")})481          this.setState({sub8:("18ECL58")})482          this.setState({sub9:("18CIV59")})}483          break;484        case '6':485          if(this.state.Title!=='6th SEM'){486            this.setState({487              c1:'4',488              c2:'4',489              c3:'4',490              c4:'3',491              c5:'3',492              c6:'2',493              c7:'2',494              c8:'2'495             })496           this.setState({Title:("6th SEM")})497          this.setState({sub1:("18EC61")})498          this.setState({sub2:("18EC62")})499          this.setState({sub3:("18EC63")})500          this.setState({sub4:("18XX64X")})501          this.setState({sub5:("18XX65X")})502          this.setState({sub6:("18ECL66")})503          this.setState({sub7:("18ECL67")})504          this.setState({sub8:("18ECMP68")})505         }506          break;507        case '7':508          if(this.state.Title!=='7th SEM'){509            this.setState({510              c1:'3',511              c2:'3',512              c3:'3',513              c4:'3',514              c5:'3',515              c6:'2',516              c7:'2',517              c8:'1'              518             })519           this.setState({Title:("7th SEM")})520          this.setState({sub1:("18EC71")})521          this.setState({sub2:("18EC72")})522          this.setState({sub3:("18XX73X")})523          this.setState({sub4:("18XX74X")})524          this.setState({sub5:("18XX75X")})525          this.setState({sub6:("18ECL76")})526          this.setState({sub7:("18ECL77")})527          this.setState({sub8:("18ECP78 ")})528          }529          break;530        case '8':531          if(this.state.Title!=='8th SEM'){532            this.setState({533              c1:'3',534              c2:'3',535              c3:'8',536              c4:'1',537              c5:'3'538                            539             })540           this.setState({Title:("8th SEM")})541          this.setState({sub1:("18EC81")})542          this.setState({sub2:("18XX82X")})543          this.setState({sub3:("18ECP83")})544          this.setState({sub4:("18ECS84")})545          }546          break;547        default:548          break;549      }550    }551    else if (this.props.brch === "eee") {552      switch (this.props.sem) {553        case '3':554          if(this.state.Title!=='3rd SEM'){555            this.setState({556              c1:'3',557              c2:'4',558              c3:'3',559              c4:'3',560              c5:'3',561              c6:'3',562              c7:'2',563              c8:'2',564              c9:'1'565             })566           this.setState({Title:("3rd SEM")})567          this.setState({sub1:("18MAT31")})568          this.setState({sub2:("18EE32")})569          this.setState({sub3:("18EE33")})570          this.setState({sub4:("18EE34")})571          this.setState({sub5:("18EE35")})572          this.setState({sub6:("18EE36")})573          this.setState({sub7:("18EEL37")})574          this.setState({sub8:("18EEL38")})575          this.setState({sub9:("18KVK39/18KAK39/18CPC39")})576          }577          break;578        case '4':579          if(this.state.Title!=='4th SEM'){580            this.setState({581              c1:'3',582              c2:'3',583              c3:'4',584              c4:'3',585              c5:'3',586              c6:'3',587              c7:'2',588              c8:'2',589              c9:'1'590             })591           this.setState({Title:("4th SEM")})592          this.setState({sub1:("18MAT41")})593          this.setState({sub2:("18EE42")})594          this.setState({sub3:("18EE43")})595          this.setState({sub4:("18EE44")})596          this.setState({sub5:("18EE45")})597          this.setState({sub6:("18EE46")})598          this.setState({sub7:("18EEL47")})599          this.setState({sub8:("18EEL48")})600          this.setState({sub9:("18KVK39/18KAK39/18CPC39")})601          }602          break;603        case '5':604          if(this.state.Title!=='5th SEM'){605            this.setState({606              c1:'3',607              c2:'4',608              c3:'4',609              c4:'3',610              c5:'3',611              c6:'3',612              c7:'2',613              c8:'2',614              c9:'1'615            616             })617           this.setState({Title:("5th SEM")})618          this.setState({sub1:("18EE51")})619          this.setState({sub2:("18EE52")})620          this.setState({sub3:("18EE53")})621          this.setState({sub4:("18EE54")})622          this.setState({sub5:("18EE55")})623          this.setState({sub6:("18EE56")})624          this.setState({sub7:("18EEL57")})625          this.setState({sub8:("18EEL58")})626          this.setState({sub9:("18CIV59")})627          }628          break;629        case '6':630          if(this.state.Title!=='6th SEM'){631            this.setState({632              c1:'4',633              c2:'4',634              c3:'4',635              c4:'3',636              c5:'3',637              c6:'2',638              c7:'2',639              c8:'2'640             })641           this.setState({Title:("6th SEM")})642          this.setState({sub1:("18EE61")})643          this.setState({sub2:("18EE62")})644          this.setState({sub3:("18EE63")})645          this.setState({sub4:("18EE64X")})646          this.setState({sub5:("18EE65X")})647          this.setState({sub6:("18EEL66")})648          this.setState({sub7:("18EEL67")})649          this.setState({sub8:("18EEMP68")})650          }651          break;652        case '7':653          if(this.state.Title!=='7th SEM'){654            this.setState({655              c1:'3',656              c2:'3',657              c3:'3',658              c4:'3',659              c5:'3',660              c6:'2',661              c7:'2',662              c8:'1'              663             })664           this.setState({Title:("7th SEM")})665          this.setState({sub1:("18EE71")})666          this.setState({sub2:("18EE72")})667          this.setState({sub3:("18EE73X")})668          this.setState({sub4:("18EE74X")})669          this.setState({sub5:("18EE75X")})670          this.setState({sub6:("18EEL76")})671          this.setState({sub7:("18EEL77")})672          this.setState({sub8:("18EEP78")})673          } 674          break;675        case '8':676          if(this.state.Title!=='8th SEM'){677            this.setState({678              c1:'3',679              c2:'3',680              c3:'8',681              c4:'1',682              c5:'3'683                            684             })685           this.setState({Title:("8th SEM")})686          this.setState({sub1:("18EE81")})687          this.setState({sub2:("18EE82")})688          this.setState({sub3:("18EEP83")})689          this.setState({sub4:("18EES84")})690          this.setState({sub5:("18EEI85")})691          }692          break;693        default:694          break;695      }696    }697    else if (this.props.brch === "me") {698      switch (this.props.sem) {699        case '3':700          if(this.state.Title!=='3rd SEM'){701            this.setState({702              c1:'3',703              c2:'4',704              c3:'3',705              c4:'3',706              c5:'3',707              c6:'3',708              c7:'2',709              c8:'2',710              c9:'1'711             })712           this.setState({Title:("3rd SEM")})713          this.setState({sub1:("18MAT31")})714          this.setState({sub2:("18ME32")})715          this.setState({sub3:("18ME33")})716          this.setState({sub4:("18ME34")})717          this.setState({sub5:("18ME35A/35B")})718          this.setState({sub6:("18ME36A/36B")})719          this.setState({sub7:("18MEL37A/37B")})720          this.setState({sub8:("18MEL38A/39B")})721          this.setState({sub9:("18KVK39/18KAK39/18CPC39")})722          }723          break;724        case '4':725          if(this.state.Title!=='4th SEM'){726            this.setState({727              c1:'3',728              c2:'4',729              c3:'3',730              c4:'3',731              c5:'3',732              c6:'3',733              c7:'2',734              c8:'2',735              c9:'1'736             })737            738           this.setState({Title:("4th SEM")})739          this.setState({sub1:("18MAT41")})740          this.setState({sub2:("18ME42")})741          this.setState({sub3:("18ME43")})742          this.setState({sub4:("18ME44")})743          this.setState({sub5:("18ME45A/45B")})744          this.setState({sub6:("18ME46A/46B")})745          this.setState({sub7:("18MEL47A/47B")})746          this.setState({sub8:("18MEL48A/48B")})747          this.setState({sub9:("18KVK39/18KAK39/18CPC39")})}748          break;749        case '5':750          if(this.state.Title!=='5th SEM'){751            this.setState({752              c1:'3',753              c2:'4',754              c3:'4',755              c4:'3',756              c5:'3',757              c6:'2',758              c7:'3',759              c8:'2',760              c9:'1'761            762             })763           this.setState({Title:("5th SEM")})764          this.setState({sub1:("18ME51")})765          this.setState({sub2:("18ME52")})766          this.setState({sub3:("18ME53")})767          this.setState({sub4:("18ME54")})768          this.setState({sub5:("18ME55")})769          this.setState({sub6:("18ME56")})770          this.setState({sub7:("18MEL57")})771          this.setState({sub8:("18MEL58")})772          this.setState({sub9:("18CIV59")})}773          break;774        case '6':775          if(this.state.Title!=='6th SEM'){776            this.setState({777              c1:'4',778              c2:'4',779              c3:'4',780              c4:'3',781              c5:'2',782              c6:'2',783              c7:'2',784              c8:'2'785             })786           this.setState({Title:("6th SEM")})787          this.setState({sub1:("18ME61")})788          this.setState({sub2:("18ME62")})789          this.setState({sub3:("18ME63")})790          this.setState({sub4:("18ME64X")})791          this.setState({sub5:("18ME65X")})792          this.setState({sub6:("18MEL66")})793          this.setState({sub7:("18MEL67")})794          this.setState({sub8:("18MEMP68")})795          }796          break;797        case '7':798          if(this.state.Title!=='7th SEM'){799            this.setState({800              c1:'3',801              c2:'3',802              c3:'3',803              c4:'3',804              c5:'3',805              c6:'2',806              c7:'2',807              c8:'1'              808             })809           this.setState({Title:("7th SEM")})810          this.setState({sub1:("18ME71")})811          this.setState({sub2:("18ME72")})812          this.setState({sub3:("18ME73X")})813          this.setState({sub4:("18ME74X")})814          this.setState({sub5:("18ME75X")})815          this.setState({sub6:("18MEL76")})816          this.setState({sub7:("18MEL77")})817          this.setState({sub8:("18MEP78")})818          }819          break;820        case '8':821          if(this.state.Title!=='8th SEM'){822            this.setState({823              c1:'3',824              c2:'3',825              c3:'8',826              c4:'1',827              c5:'3'828                            829             })830           this.setState({Title:("8th SEM")})831          this.setState({sub1:("18ME81")})832          this.setState({sub2:("18ME82X")})833          this.setState({sub3:("18MEP83")})834          this.setState({sub4:("18MES84")})835          this.setState({sub5:("18XXI85")})836          }837          break;838        default:839          break;840      }841    }842    else if (this.props.brch === "civil") {843      switch (this.props.sem) {844        case '3':845          if(this.state.Title!=='3rd SEM'){846            this.setState({847              c1:'3',848              c2:'4',849              c3:'3',850              c4:'3',851              c5:'3',852              c6:'3',853              c7:'2',854              c8:'2',855              c9:'1'856             })857           this.setState({Title:("3rd SEM")})858          this.setState({sub1:("18MAT31")})859          this.setState({sub2:("18CV32")})860          this.setState({sub3:("18CV33")})861          this.setState({sub4:("18CV34")})862          this.setState({sub5:("18CV35")})863          this.setState({sub6:("18CV36")})864          this.setState({sub7:("18CVL37")})865          this.setState({sub8:("18CVL38")})866          this.setState({sub9:("18KVK39/18KAK39/18CPC39")})867          }868          break;869        case '4':870          if(this.state.Title!=='4th SEM'){871            this.setState({872              c1:'3',873              c2:'4',874              c3:'3',875              c4:'3',876              c5:'3',877              c6:'3',878              c7:'2',879              c8:'2',880              c9:'1'881             })882           this.setState({Title:("4th SEM")})883          this.setState({sub1:("18MAT41")})884          this.setState({sub2:("18CV42")})885          this.setState({sub3:("18CV43")})886          this.setState({sub4:("18CV44")})887          this.setState({sub5:("18CV45")})888          this.setState({sub6:("18CV46")})889          this.setState({sub7:("18CVL47")})890          this.setState({sub8:("18CVL48")})891          this.setState({sub9:("18KVK39/18KAK39/18CPC39")})}892          break;893        case '5':894          if(this.state.Title!=='5th SEM'){895            this.setState({896              c1:'3',897              c2:'4',898              c3:'4',899              c4:'3',900              c5:'3',901              c6:'3',902              c7:'2',903              c8:'2',904              c9:'1'905            906             })907           this.setState({Title:("5th SEM")}) 908          this.setState({sub1:("18CV51")})909          this.setState({sub2:("18CV52")})910          this.setState({sub3:("18CV53")})911          this.setState({sub4:("18CV54")})912          this.setState({sub5:("18CV55")})913          this.setState({sub6:("18CV56")})914          this.setState({sub7:("18CVL57")})915          this.setState({sub8:("18CVL58")})916          this.setState({sub9:("18CIV59")})}917          break;918        case '6':919          if(this.state.Title!=='6th SEM'){920            this.setState({921              c1:'4',922              c2:'4',923              c3:'4',924              c4:'3',925              c5:'3',926              c6:'2',927              c7:'2',928              c8:'2'929             })930           this.setState({Title:("6th SEM")})931          this.setState({sub1:("18CV61")})932          this.setState({sub2:("18CV62")})933          this.setState({sub3:("18CV63")})934          this.setState({sub4:("18CV64X")})935          this.setState({sub5:("18CV65X")})936          this.setState({sub6:("18CVL66")})937          this.setState({sub7:("18CVL67")})938          this.setState({sub8:("18CVEP68")})939          }940          break;941        case '7':942          if(this.state.Title!=='7th SEM'){943            this.setState({944              c1:'3',945              c2:'3',946              c3:'3',947              c4:'3',948              c5:'3',949              c6:'2',950              c7:'2',951              c8:'1'              952             })953           this.setState({Title:("7th SEM")})954          this.setState({sub1:("18CV71")})955          this.setState({sub2:("18CV72")})956          this.setState({sub3:("18CV73X")})957          this.setState({sub4:("18CV74X")})958          this.setState({sub5:("18CV75X")})959          this.setState({sub6:("18CVL76")})960          this.setState({sub7:("18CVL77")})961          this.setState({sub8:("18CVP78")})}962          break;963        case '8':964          if(this.state.Title!=='8th SEM'){965            this.setState({966              c1:'3',967              c2:'3',968              c3:'8',969              c4:'1',970              c5:'3'971                            972             })973           this.setState({Title:("8th SEM")})974          this.setState({sub1:("18CV81")})975          this.setState({sub2:("18CV82X")})976          this.setState({sub3:("18CVP83")})977          this.setState({sub4:("18CVS84")})978          this.setState({sub5:("18CVI85")})979          }980          break;981        default:982          break;983      }984    }985    return (986      <div>987        <div className="head">988          <h1>{this.state.Title}</h1>989        </div>990        <div className="subhead">991          <h3>Subjects</h3>992        </div>993        <form action="/ ">994          <div className="marks">995            {996              this.state.sub1?997            (<div className="sub">998              <div className="subname">999                <h5>{this.state.sub1} -</h5>1000              </div>1001              <div className="form">1002                <input1003                  type="number"1004                  min="0"1005                  max="100"1006                  placeholder="0"1007                  value={this.state.m1}1008                  onChange={this.handlenum1}1009                  required1010                />1011              </div>1012            </div>)1013            :(console.log('hello'))1014            }1015            {1016            this.state.sub2?1017              (<div className="sub">1018              <div className="subname">1019                <h5>{this.state.sub2} -</h5>1020              </div>1021              <div className="form">1022                <input1023                  type="number"1024                  min="0"1025                  max="100"1026                  placeholder="0"1027                  value={this.state.m2}1028                  onChange={this.handleChange2}1029                  required1030                  />1031              </div>1032            </div>)1033            :(console.log('hello'))1034            }1035            {1036              this.state.sub3?1037            (<div className="sub">1038              <div className="subname">1039                <h5>{this.state.sub3} -</h5>1040              </div>1041              <div className="form">1042                <input1043                  type="number"1044                  min="0"1045                  max="100"1046                  placeholder="0"1047                  value={this.state.m3}1048                  onChange={this.handleChange3}1049                  required1050                />1051              </div>1052            </div>)1053            :(console.log('hello'))1054            }1055            {1056              this.state.sub4?1057            (<div className="sub">1058              <div className="subname">1059                <h5>{this.state.sub4} -</h5>1060              </div>1061              <div className="form">1062                <input1063                  type="number"1064                  min="0"1065                  max="100"1066                  placeholder="0"1067                  value={this.state.m4}1068                  onChange={this.handleChange4}1069                  required1070                />1071              </div>1072            </div>)1073            :(console.log('hello'))1074            }1075            {1076              this.state.sub5?1077            (<div className="sub">1078              <div className="subname">1079                <h5>{this.state.sub5} -</h5>1080              </div>1081              <div className="form">1082                <input1083                  type="number"1084                  min="0"1085                  max="100"1086                  placeholder="0"1087                  value={this.state.m5}1088                  onChange={this.handleChange5}1089                  required1090                />1091              </div>1092            </div>)1093            :(console.log('hello'))1094            }1095            {1096              this.state.sub6?1097            (<div className="sub">1098              <div className="subname">1099                <h5>{this.state.sub6} -</h5>1100              </div>1101              <div className="form">1102                <input1103                  type="number"1104                  min="0"1105                  max="100"1106                  placeholder="0"1107                  value={this.state.m6}1108                  onChange={this.handleChange6}1109                  required1110                />1111              </div>1112            </div>)1113            :(console.log('hello'))1114            }1115            {1116              this.state.sub7?1117            (<div className="sub">1118              <div className="subname">1119                <h5>{this.state.sub7} -</h5>1120              </div>1121              <div className="form">1122                <input1123                  type="number"1124                  min="0"1125                  max="100"1126                  placeholder="0"1127                  value={this.state.m7}1128                  onChange={this.handleChange7}1129                  required1130                />1131              </div>1132            </div>)1133            :(console.log('hello'))1134            }1135            {1136              this.state.sub8?1137            (<div className="sub">1138              <div className="subname">1139                <h5>{this.state.sub8} -</h5>1140              </div>1141              <div className="form">1142                <input1143                  type="number"1144                  min="0"1145                  max="100"1146                  placeholder="0"1147                  value={this.state.m8}1148                  onChange={this.handleChange8}1149                  required1150                />1151              </div>1152            </div>)1153            :(console.log('hello'))1154            }1155            {1156            this.state.sub9?1157            (<div className="sub">1158              <div className="subname">1159                <h5>{this.state.sub9} -</h5>1160              </div>1161              <div className="form">1162                <input1163                  type="number"1164                  min="0"1165                  max="100"1166                  placeholder="0"1167                  value={this.state.m9}1168                  onChange={this.handleChange9}1169                  required1170                />1171              </div>1172            </div>)1173            :console.log('hello')1174            }1175            <div className="btn">1176                                 <button  onClick={this.exe}>Submit</button>1177            </div>1178                                {1179                                this.state.print?1180                                (<h1 className='result'>Your SGPA : {Number(Number((this.state.x1)*Number(this.state.c1)+(this.state.x2)*Number(this.state.c2)+(this.state.x3)*Number(this.state.c3)+(this.state.x4)*Number(this.state.c4)+(this.state.x5)*Number(this.state.c5)+(this.state.x6)*Number(this.state.c6)+(this.state.x7)*Number(this.state.c7)+(this.state.x8)*Number(this.state.c8)+(this.state.x9)*Number(this.state.c9))/this.state.t2).toFixed(2)}</h1>)1181                                :(null)1182                                }1183          </div>1184        </form>1185      </div>1186    );1187  }1188}...set.py
Source:set.py  
1# -*- coding: utf-8 -*-2"""Immutable set state."""3from typing import TYPE_CHECKING, TypeVar, cast4try:5    import collections.abc as collections_abc6except ImportError:7    import collections as collections_abc  # type: ignore8from pyrsistent import pset9from six import iteritems10from .._bases import BaseInteractiveSet, final11from ..utils.custom_repr import custom_iterable_repr, custom_mapping_repr12from ..utils.recursive_repr import recursive_repr13from .bases import BaseState14if TYPE_CHECKING:15    from typing import Any, Iterable, Iterator, Type16    from pyrsistent.typing import PSet17__all__ = ["SetState"]18T = TypeVar("T")  # Any type.19# noinspection PyTypeChecker20_SS = TypeVar("_SS", bound="SetState")21@final22class SetState(BaseState[T], BaseInteractiveSet[T]):23    """24    Immutable set state.25    Inherits from:26      - :class:`objetto.bases.BaseState`27      - :class:`objetto.bases.BaseInteractiveSet`28    :param initial: Initial values.29    :type initial: collections.abc.Iterable30    """31    __slots__ = ()32    @classmethod33    def _make(cls, internal=pset()):34        # type: (Type[_SS], PSet[T]) -> _SS35        """36        Make new state by directly setting the internal state.37        :param internal: Internal state.38        :return: State.39        """40        return super(SetState, cls)._make(internal)41    @staticmethod42    def _make_internal(initial):43        # type: (Iterable[T]) -> PSet[T]44        """45        Initialize internal state.46        :param initial: Initial values.47        """48        return pset(initial)49    @classmethod50    def _from_iterable(cls, iterable):51        # type: (Iterable) -> SetState52        """53        Make set state from iterable.54        :param iterable: Iterable.55        :type iterable: collections.abc.Iterable56        :return: Set state.57        :rtype: objetto.states.SetState58        """59        if isinstance(iterable, type(pset())):60            return SetState._make(iterable)61        else:62            return SetState(iterable)63    def __init__(self, initial=()):64        # type: (Iterable[T]) -> None65        super(SetState, self).__init__(initial=initial)66    def __hash__(self):67        # type: () -> int68        """69        Get hash.70        :return: Hash.71        :rtype: int72        """73        return super(SetState, self).__hash__()74    def __eq__(self, other):75        # type: (object) -> bool76        """77        Compare for equality.78        :param other: Another object.79        :return: True if equal.80        :rtype: bool81        """82        if self is other:83            return True84        if not isinstance(other, collections_abc.Hashable):85            return self._internal == other86        if isinstance(other, SetState):87            return self._internal == other._internal88        return False89    def __contains__(self, value):90        # type: (Any) -> bool91        """92        Get whether value is present.93        :param value: Value.94        :type value: collections.abc.Hashable95        :return: True if contains.96        :rtype: bool97        """98        return value in self._internal99    def __iter__(self):100        # type: () -> Iterator[T]101        """102        Iterate over values.103        :return: Values iterator.104        :rtype: collections.abc.Iterator[collections.abc.Hashable]105        """106        for key in self._internal:107            yield key108    def __len__(self):109        # type: () -> int110        """111        Get value count.112        :return: Value count.113        :rtype: int114        """115        return len(self._internal)116    @recursive_repr117    def __repr__(self):118        # type: () -> str119        """120        Get representation.121        :return: Representation.122        :rtype: str123        """124        return custom_iterable_repr(125            self._internal,126            prefix="{}([".format(type(self).__name__),127            suffix="])",128            sorting=True,129            sort_key=lambda v: hash(v),130        )131    def _hash(self):132        # type: () -> int133        """134        Get hash.135        :return: Hash.136        :rtype: int137        """138        return hash(self)139    def _clear(self):140        # type: (_SS) -> _SS141        """142        Clear.143        :return: Transformed.144        :rtype: objetto.states.SetState145        """146        return self._make()147    def _add(self, value):148        # type: (_SS, T) -> _SS149        """150        Add value.151        :param value: Value.152        :type value: collections.abc.Hashable153        :return: Transformed.154        :rtype: objetto.states.SetState155        """156        return self._make(self._internal.add(value))157    def _discard(self, *values):158        # type: (_SS, T) -> _SS159        """160        Discard value(s).161        :param values: Value(s).162        :type values: collections.abc.Hashable163        :return: Transformed.164        :rtype: objetto.states.SetState165        :raises ValueError: No values provided.166        """167        if not values:168            error = "no values provided"169            raise ValueError(error)170        return self._make(self._internal.discard(*values))171    def _remove(self, *values):172        # type: (_SS, T) -> _SS173        """174        Remove existing value(s).175        :param values: Value(s).176        :type values: collections.abc.Hashable177        :return: Transformed.178        :rtype: objetto.states.SetState179        :raises ValueError: No values provided.180        :raises KeyError: Value is not present.181        """182        if not values:183            error = "no values provided"184            raise ValueError(error)185        return self._make(self._internal.difference(values))186    def _replace(self, old_value, new_value):187        # type: (_SS, T, T) -> _SS188        """189        Replace existing value with a new one.190        :param old_value: Existing value.191        :type old_value: collections.abc.Hashable192        :param new_value: New value.193        :type new_value: collections.abc.Hashable194        :return: Transformed.195        :rtype: objetto.states.SetState196        :raises KeyError: Value is not present.197        """198        return self._make(self._internal.remove(old_value).add(new_value))199    def _update(self, iterable):200        # type: (_SS, Iterable[T]) -> _SS201        """202        Update with iterable.203        :param iterable: Iterable.204        :type iterable: collections.abc.Iterable[collections.abc.Hashable]205        :return: Transformed.206        :rtype: objetto.states.SetState207        """208        return self._make(self._internal.update(iterable))209    def isdisjoint(self, iterable):210        # type: (Iterable) -> bool211        """212        Get whether is a disjoint set of an iterable.213        :param iterable: Iterable.214        :type iterable: collections.abc.Iterable215        :return: True if is disjoint.216        :rtype: bool217        """218        return self._internal.isdisjoint(iterable)219    def issubset(self, iterable):220        # type: (Iterable) -> bool221        """222        Get whether is a subset of an iterable.223        :param iterable: Iterable.224        :type iterable: collections.abc.Iterable225        :return: True if is subset.226        :rtype: bool227        """228        return self._internal.issubset(iterable)229    def issuperset(self, iterable):230        # type: (Iterable) -> bool231        """232        Get whether is a superset of an iterable.233        :param iterable: Iterable.234        :type iterable: collections.abc.Iterable235        :return: True if is superset.236        :rtype: bool237        """238        return self._internal.issuperset(iterable)239    def intersection(self, iterable):240        # type: (Iterable) -> SetState241        """242        Get intersection.243        :param iterable: Iterable.244        :type iterable: collections.abc.Iterable245        :return: Intersection.246        :rtype: objetto.states.SetState247        """248        return SetState._make(self._internal.intersection(iterable))249    def difference(self, iterable):250        # type: (Iterable) -> SetState251        """252        Get difference.253        :param iterable: Iterable.254        :type iterable: collections.abc.Iterable255        :return: Difference.256        :rtype: objetto.states.SetState257        """258        return SetState._make(self._internal.difference(iterable))259    def inverse_difference(self, iterable):260        # type: (Iterable) -> SetState261        """262        Get an iterable's difference to this.263        :param iterable: Iterable.264        :type iterable: collections.abc.Iterable265        :return: Inverse Difference.266        :rtype: objetto.states.SetState267        """268        return SetState._make(pset(iterable).difference(self._internal))269    def symmetric_difference(self, iterable):270        # type: (Iterable) -> SetState271        """272        Get symmetric difference.273        :param iterable: Iterable.274        :type iterable: collections.abc.Iterable275        :return: Symmetric difference.276        :rtype: objetto.states.SetState277        """278        return SetState._make(self._internal.symmetric_difference(iterable))279    def union(self, iterable):280        # type: (Iterable) -> SetState281        """282        Get union.283        :param iterable: Iterable.284        :type iterable: collections.abc.Iterable285        :return: Union.286        :rtype: objetto.states.SetState287        """288        return SetState._make(self._internal.union(iterable))289    def find_with_attributes(self, **attributes):290        # type: (Any) -> T291        """292        Find first value that matches unique attribute values.293        :param attributes: Attributes to match.294        :return: Value that has matching attributes.295        :raises ValueError: No attributes provided or no match found.296        """297        if not attributes:298            error = "no attributes provided"299            raise ValueError(error)300        for value in self._internal:301            for a_name, a_value in iteritems(attributes):302                if not hasattr(value, a_name) or getattr(value, a_name) != a_value:303                    break304            else:305                return value306        error = "could not find a match for {}".format(307            custom_mapping_repr(308                attributes,309                prefix="(",310                template="{key}={value}",311                suffix=")",312                key_repr=str,313            ),314        )315        raise ValueError(error)316    @property317    def _internal(self):318        # type: () -> PSet[T]319        """Internal values."""...sidebar.jsx
Source:sidebar.jsx  
1import React, { Component } from 'react'2import {Link} from 'react-router-dom';3class Sidebar extends Component {4    constructor(props){5        super(props)6        this.state = {7            hideDropdown1:0,8            username:"",9            profilepic:"",10            sb1: "#0f8d83",11            sb2: "#818181",12            sb3: "#818181",13            sb4: "#818181",14            sb5: "#818181",15            sb6: "#818181",16            sb7: "#818181",17            sb8: "#818181",18            sb9: "#818181"19        }20        this.handleDropdownClick = this.handleDropdownClick.bind(this);21        this.changeSb1 = this.changeSb1.bind(this)22        this.changeSb2 = this.changeSb2.bind(this)23        this.changeSb3 = this.changeSb3.bind(this)24        this.changeSb5 = this.changeSb5.bind(this)25        this.changeSb6 = this.changeSb6.bind(this)26        this.changeSb7 = this.changeSb7.bind(this)27        this.changeSb8 = this.changeSb8.bind(this)28        this.changeSb9 = this.changeSb9.bind(this)29    }30    componentDidMount(){31        this._isMounted = true;32        var username = window.atob(localStorage.getItem('username'))33         this.setState({username: username})34        var currUrl = window.location.pathname;35        if(currUrl == "/control") this.changeSb2();36        else if(currUrl == "/addDevice") this.changeSb3();37        else if(currUrl == "/myareas") this.changeSb5();38        else if(currUrl == "/manageareas") this.changeSb6();39        else if(currUrl == "/rules") this.changeSb7();40        else if(currUrl == "/user") this.changeSb8();41    }42    componentWillUnmount() {43        this._isMounted = false;44    }45    handleLogout(){46        var username = window.atob(localStorage.getItem('username'))47        alert("logout")48        localStorage.removeItem("username")49        localStorage.removeItem("token")50        axios.post('/api/logout', {51            username:username,52            currentAccessToken:window.atob(localStorage.getItem('token')),53        })54    }55    handleDropdownClick(){56        if(this.state.hideDropdown1 == 0){57            document.querySelector('.dropdown-container').style.display = 'block';58            this.setState({hideDropdown1:1})59        }60        else if(this.state.hideDropdown1 == 1){61            document.querySelector('.dropdown-container').style.display = 'none';62            this.setState({hideDropdown1:0})63        }64    }65    changeSb1(){var active = "#0f8d83";var inactive = "#818181";this.setState({sb1:active});this.setState({sb2:inactive});this.setState({sb3:inactive});this.setState({sb4:inactive});this.setState({sb5:inactive});this.setState({sb6:inactive});this.setState({sb7:inactive});this.setState({sb8:inactive});this.setState({sb9:inactive});}66    changeSb2(){var active = "#0f8d83";var inactive = "#818181";this.setState({sb1:inactive});this.setState({sb2:active});this.setState({sb3:inactive});this.setState({sb4:inactive});this.setState({sb5:inactive});this.setState({sb6:inactive});this.setState({sb7:inactive});this.setState({sb8:inactive});this.setState({sb9:inactive});}67    changeSb3(){var active = "#0f8d83";var inactive = "#818181";this.setState({sb1:inactive});this.setState({sb2:inactive});this.setState({sb3:active});this.setState({sb4:inactive});this.setState({sb5:inactive});this.setState({sb6:inactive});this.setState({sb7:inactive});this.setState({sb8:inactive});this.setState({sb9:inactive});}68    changeSb5(){var active = "#0f8d83";var inactive = "#818181";this.setState({sb1:inactive});this.setState({sb2:inactive});this.setState({sb3:inactive});this.setState({sb4:active});this.setState({sb5:active});this.setState({sb6:inactive});this.setState({sb7:inactive});this.setState({sb8:inactive});this.setState({sb9:inactive});}69    changeSb6(){var active = "#0f8d83";var inactive = "#818181";this.setState({sb1:inactive});this.setState({sb2:inactive});this.setState({sb3:inactive});this.setState({sb4:active});this.setState({sb5:inactive});this.setState({sb6:active});this.setState({sb7:inactive});this.setState({sb8:inactive});this.setState({sb9:inactive});}70    changeSb7(){var active = "#0f8d83";var inactive = "#818181";this.setState({sb1:inactive});this.setState({sb2:inactive});this.setState({sb3:inactive});this.setState({sb4:inactive});this.setState({sb5:inactive});this.setState({sb6:inactive});this.setState({sb7:active});this.setState({sb8:inactive});this.setState({sb9:inactive});}71    changeSb8(){var active = "#0f8d83";var inactive = "#818181";this.setState({sb1:inactive});this.setState({sb2:inactive});this.setState({sb3:inactive});this.setState({sb4:inactive});this.setState({sb5:inactive});this.setState({sb6:inactive});this.setState({sb7:inactive});this.setState({sb8:active});this.setState({sb9:inactive});}72    changeSb8(){var active = "#0f8d83";var inactive = "#818181";this.setState({sb1:inactive});this.setState({sb2:inactive});this.setState({sb3:inactive});this.setState({sb4:inactive});this.setState({sb5:inactive});this.setState({sb6:inactive});this.setState({sb7:inactive});this.setState({sb8:active});this.setState({sb9:inactive});}73    changeSb9(){var active = "#0f8d83";var inactive = "#818181";this.setState({sb1:inactive});this.setState({sb2:inactive});this.setState({sb3:inactive});this.setState({sb4:inactive});this.setState({sb5:inactive});this.setState({sb6:inactive});this.setState({sb7:inactive});this.setState({sb8:inactive});this.setState({sb9:active});}74    render() {75        return (76            <React.Fragment>77                <div className="sidebar josefin-font">78                    {/* <h1 className="text-center josefin-font pt-2">IoT</h1> */}79                    <div className="w-100 text-center pt-4">80                        <img src='pictures/icon2.png' alt="logo" width={"30%"} />81                    </div>82                    <h5 className="text-center josefin-font" style={{color:"#0f8d83", fontSize:"medium"}}>Hi, <i className="fas fa-user" style={{fontSize:"20px",marginBottom:"30px"}}></i> {this.state.username}</h5>83                    <Link to="/dashboard"  onClick={this.changeSb1}>84                        <i className="fas fa-chart-line icon-style" style={{color:this.state.sb1}}></i>85                        <span className="link-name" style={{color:this.state.sb1}}> Dashboard</span>86                    </Link>87                    <Link to="/control" onClick={this.changeSb2}>88                        <i className="fas fa-toggle-off icon-style" style={{ color:this.state.sb2}} ></i>89                        <span className="link-name" style={{color:this.state.sb2}}> All Devices</span>90                    </Link>91                    <Link to="/addDevice" onClick={this.changeSb3}>92                        <i className="fas fa-plus-circle icon-style" style={{ color:this.state.sb3}} >93                            </i><span className="link-name" style={{color:this.state.sb3}}> Add Devices</span>94                    </Link>95                    <button className="dropdown-btn" onClick={this.handleDropdownClick}>96                        <i className="fas fa-map-marked-alt icon-style" style={{fontSize:"20px",marginBottom:"10px" ,color:this.state.sb4}}></i>97                        <span className="link-name" style={{color:this.state.sb4}}> Areas</span>98                           <i className="fa fa-caret-down"></i>99                    </button>100                    <div className="dropdown-container">101                        <Link to="/myareas" onClick={this.changeSb5}>102                            <span className="dropdown-sublink"  style={{color:this.state.sb5}}> My Areas </span>103                        </Link>104                        <Link to="/manageareas" onClick={this.changeSb6}>105                            <span className="dropdown-sublink" style={{color:this.state.sb6}}> Manage Areas </span>106                        </Link>107                    </div>108                    <Link to="/rules" onClick={this.changeSb7}>109                        <i className="fas fa-list-alt icon-style" style={{ color:this.state.sb7}} ></i>110                        <span className="link-name" style={{color:this.state.sb7}}> Rules</span>111                    </Link>112                    <Link to="/voices" onClick={this.changeSb9}>113                        <i className="fas fa-microphone icon-style" style={{ color:this.state.sb9}} ></i>114                        <span className="link-name" style={{color:this.state.sb9}}>  Voice</span>115                    </Link>116                    <Link to="/user" onClick={this.changeSb8}>117                        <i className="fas fa-user-cog icon-style" style={{ color:this.state.sb8}} ></i>118                        <span className="link-name" style={{color:this.state.sb8}}>Account</span>119                    </Link>120                    <div className="">121                        <div className="logout">122                            <a onClick={this.handleLogout} href="/">123                                <i className="fas fa-power-off icon-style" ></i>124                                <span className="link-name">  Logout</span>125                            </a>126                        </div>127                    </div>128                </div>129            </React.Fragment>130        );131    }132}...TestState.js
Source:TestState.js  
1import React from 'react'2// å¦ä¹ ç®æ ï¼æ·±å
¥çè§£stateçç¹ç¹ï¼å£°æå¼ï¼ï¼å¦ä¹ this.setState()è¿ä¸ªæ¹æ³ç使ç¨ã3// 1ãæä¹çè§£â声æå¼âï¼4// 彿们éè¦æ¸²æ(æä½)çé¢èç¹æ¶ï¼æä»¬å
声æä¸ä¸ªstateåéï¼å使ç¨è¿ä¸ªstateåéå»åä¸è§å¾èç¹ç渲ææäº¤äºã5// æç¤ºï¼stateåéåªè½å¨constructorä¸è¿è¡å®ä¹ã6// 声æå¼åéçç¹ç¹ï¼å½ä½¿ç¨this.setState()æ¥ä¿®æ¹stateåéæ¶ï¼ä¼è§¦årender()æ¹æ³å次æ§è¡ï¼è¿åæ°çJSXï¼Fiberæ ï¼ï¼åè¿ä¸æ¥æ§è¡diffè¿ç®(åè°è¿ç®)ï¼commitæäº¤æ´æ°è§å¾ã7// å¦ä½å®ä¹stateï¼å¦ä½ä½¿ç¨stateï¼å¦ä½ä¿®æ¹stateï¼8// 2ã详ç»ä»ç»this.setState()è¿ä¸ªä¸å±æ¹æ³ã9// è¯æ³1ï¼this.setState({},callback)  å½æä»¬ä¿®æ¹stateæ¶ï¼æ°å¼ä¸æ§å¼æ å
³æ¶ï¼å»ºè®®ç¨è¯æ³1ã10// è¯æ³2ï¼this.setState((state,props)=>({}), callback)  å½æä»¬ä¿®æ¹stateæ¶ï¼æ°å¼æ¯ç±æ§å¼è®¡ç®èæ¥ï¼å»ºè®®ç¨è¯æ³2ã11// this.setState(xx, callback) è¿ä¸ªcallbackè¡¨ç¤ºå¼æ¥æ§è¡stateæ´æ°ä»»å¡å·²å®æã12// 注æï¼stateå¯ä»¥åä¸è¿ç®ï¼ä½ä¸å»ºè®®ç´æ¥ä¿®æ¹stateãå¨ä¸å¡é»è¾ä¸ï¼ä½ å¯ä»¥`const num = this.state.num + 100`ï¼ä½ä¸å»ºè®®åè¿æ ·ç代ç `this.state.num++`ã13// 注æï¼å¨reactä¸ï¼ä¿®æ¹stateåªè½ä½¿ç¨this.setState()æ¥ä¿®æ¹ï¼ä¸è¦ç´æ¥ä¿®æ¹stateãåå æ¯ç´æ¥ä¿®æ¹stateï¼ä¸ä¼è§¦årender()ï¼åªæä½¿ç¨this.setState()æ¥ä¿®æ¹stateï¼æä¼è§¦årender()ã14// 注æï¼this.setState()å¨åæäºä»¶ãçå½å¨æé©å彿°ä¸ï¼é»è®¤æ¯å¼æ¥çã为ä»ä¹æ¯å¼æ¥çå¢ï¼ä¸ºäºæ§è½ä¼å(å°½å¯è½å°åå°æ²¡å¿
è¦çrender()æ§è¡)ï¼æä»¥react宿¹å°è£
äºä¸ç³»åçåæäºä»¶(交äºäºä»¶ãçå½å¨æ)ï¼å¨åæäºä»¶ä¸æthis.setState()åæå¼æ¥çï¼ç®çæ¯åå¹¶å¤ä¸ªå¼æ¥çthis.setState()ï¼åå°æ²¡å¿
è¦çrender()ã15// å¨åæäºä»¶(交äºäºä»¶ãçå½å¨æ)ä¸ï¼this.setState()æ¯å¼æ¥çï¼å½æå¤ä¸ªthis.setState()æ¶ï¼Reactä¼èªå¨å°å®ä»¬åå¹¶èµ·æ¥çã16// å¨å®æ¶å¨(setTimeout/setInterval)ãPromise.then()ä¸ï¼this.setState()æ¯åæ¥çï¼æä»¥Reactä¸ä¼å¯¹å¤ä¸ªthis.setState()è¿è¡åå¹¶ã17export default class TestState extends React.Component {18  constructor (props) {19    super(props)20    // å¨è¿éå®ä¹å£°æå¼åé21    this.state = {22      info: {23        name: 'ganteng',24        age: 2025      },26      count: 127    }28  }29  addHandle () {30    // this.setState({31    //   count: this.state.count + 132    // }, ()=>{33    //   console.log('1--new state count', this.state.count)34    // })35    // this.setState((state)=>{36    //   // do something37    //   return {38    //     count: state.count + 139    //   }40    // }, ()=>{41    //   console.log('1--new state count', this.state.count)42    // })43    this.setState((state)=>({44      count: state.count + 545    }), ()=>{46      console.log('1--new state count', this.state.count)47    })48    console.log('2--new state count', this.state.count)49  }50  countChange1 () {51    // éæ±ï¼æcountåæ1000052    this.setState({count: 10000})53  }54  countChange2 () {55    // æ§è¡å æ¬¡render()ï¼åªæ§è¡ä¸æ¬¡ï¼reactä¼èªå¨åå¹¶ä¸é¢è¿äºthis.setState()56    // this.setState({57    //   count: 100,58    //   info: { name: 'junjie', age: 30 }59    // })60    // this.setState({61    //   count: 20062    // })63    // çä»·äº64    this.setState({65      count: 200,66      info: { name: 'junjie', age: 30 }67    })68  }69  xxxHandle () {70    this.setState({71      a: 1,72      b: 173    })74    this.setState({75      c: 2,76      d: 277    })78    this.setState(state=>({79      a: state.a + 100,80      c: state.c + 20081    }))82    this.setState(state=>{83      const newD = state.d + 30084      return {85        d: newD86      }87    })88    // åå¹¶çç»æï¼ä½ èªæµä¸ä¸ï¼89    this.setState(state=>({90      a: state.a + 100,91      b: 1,92      c: state.c + 200,93      d: state.d + 30094    }))95  }96  countChange3 () {97    setTimeout(()=>{98      // å¨å®æ¶å¨æPromise.then()æ¹æ³ä¸ï¼this.setState()æ¯åæ¥ç代ç ã99      // å¨è¿éï¼å ä¸ºthis.setState()æ¯åæ¥çï¼æä»¥Reactä¸ä¼å¯¹å®ä»¬è¿è¡åå¹¶ã100      // 妿ä¸å®è¦ç»ä¸ä¸ªè§£éï¼ä½ å¯è¿ä¹æ³ï¼å ä¸ºå®æ¶å¨æ¯å®ä»»å¡ï¼ä¸å¨åæäºä»¶çä½ç¨åèå´å
ï¼Reactæ æ³æ§å¶this.setState()ç弿¥æ§ã101      this.setState(state=>({102        count: state.count + 2103      }), ()=>{104        console.log('1--new state count', this.state.count)105      })106      this.setState(state=>({107        count: state.count - 1108      }), ()=>{109        console.log('2--new state count', this.state.count)110      })111      console.log('3--new state count', this.state.count)112    }, 0)113  }114  render () {115    const { info, count } = this.state116    console.log('--render')117    return (118      <div>119        <h1>å¦ä¹ state</h1>120        <hr/>121        <h2>ç¨æ·åï¼{ info.name }</h2>122        <h2>å¹´é¾ï¼{ info.age }</h2>123        <hr/>124        <h1>{ count }</h1>125        <button onClick={()=>this.addHandle()}>èªå¢</button>126        <button onClick={()=>this.countChange1()}>åæä¸ä¸</button>127        <button onClick={()=>this.countChange2()}>æ¹åæ°é</button>128        <button onClick={()=>this.countChange3()}>å»¶æ¶æ¹åæ°é</button>129      </div>130    )131  }...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
