JS - click and not jump to top with preventDefault()

0 votes
363 views
added Mar 6, 2019 in Javascript by LC Marshal Captain (25,790 points)
retagged May 17, 2019 by LC Marshal
  handleToggle(e) {
    e.preventDefault();
    this.setState( {
      isExpanded: !this.state.isExpanded
    })
  }

 

2 Responses

0 votes
responded May 17, 2019 by LC Marshal Captain (25,790 points)
handleClick(e) {
  e.preventDefault();
  const { onClick } = this.props;
  onClick(e);
}

 

0 votes
responded May 17, 2019 by LC Marshal Captain (25,790 points)
dancingDodo = e => {
 e.preventDefault();
 // do dancingDodo here
}

render() {
    return(
        <a onClick={this.dancingDodo} href="/">Dododo</a>
    );
}

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...