Outils pour utilisateurs

Outils du site


dev:reactdiver
console.log(id)

Appel fonction sur bouton

handleclick() {console.log("kjhdfskhsd");}
<button onClick={this.handleclick}>Cliquez moi</button>

THIS

avec BIND

handleclick() { console.log("this.state");  }
<button onClick={this.handleclick.bind(this)}>Cliquez moi</button>

avec zero fonction (plug de babel)

handleclick() { console.log("this.state");  }
<button onClick={ () => this.handleclick()}>Cliquez moi</button>

avec fonction fléchée (plug de babel)

 handleclick = () => { console.log(this.state);}

 <button onClick={this.handleclick}>Cliquez moi</button>
      

SETSTATE

 handleclick = () => {
  this.setState({compteur: this.state.compteur+1});
  console.log(this.state);
 }

ou

handleclick = () => {
  const clients = this.state.clients.slice(); 
  clients.push({id:4, nom: 'tete'});
  this.setState({clients:clients})
 };
    
dev/reactdiver.txt · Dernière modification : 2021/12/28 13:30 de sbestel