react onclick open new component code example

Example 1: react bind function to component

class Foo extends Component {
  constructor(props) {
    super(props);
    this.handleClick = this.handleClick.bind(this);
  }
  handleClick() {
    console.log('Click happened');
  }
  render() {
    return ;
  }
}

Example 2: onclick re

handleClick(id) {

    this.setState({

        vote_status: !this.state.vote_status,

    })

    let vote_object = {
        voting_object: id,
        post_id: this.props.postId
    }
    this.props.submitvote(vote_object)

    //this.forceUpdate()
}

render() {

    console.log("getVoteStatus", this.props.getVoteStatus)

    let {contents, submitvote, postId, voted_id} = this.props

    return (

        

{ this.handleClick(contents.post_poll_content_id); }}> {contents.content}

{contents.votes}% (Votes:)

); };

Tags:

Misc Example