change boolean value on click react

Solutions on MaxInterview for change boolean value on click react by the best coders in the world

showing results for - "change boolean value on click react"
Marissa
24 Jun 2016
1class Q1 extends Component {
2
3constructor(props) {
4     super(props);
5    this.state = { page1: false,
6    page2:false,
7  page3:false }
8    this.handleClick1= this.handleClick1.bind(this);
9    this.handleClick2= this.handleClick2.bind(this);
10    this.handleClick3= this.handleClick3.bind(this);
11  }
12
13  handleClick1() {
14    this.setState({ page1: true}) 
15    console.log("button1 clicked")
16}
17
18  handleClick2() {
19    this.setState({ page2: true}) 
20    console.log("button2 clicked")
21}
22
23  handleClick3() {
24    this.setState({ page3: true}) 
25    console.log("button3 clicked ")
26}
27
28  render() {
29
30        return ( 
31          <div>
32  <button onClick={this.handleClick1}
33  >Event Giveaway</button><br/>
34
35  <button onClick={this.handleClick2}
36  >Corporate Merchandise</button><br/>
37
38  <button onClick={this.handleClick3}>
39    Rewards & Recognition</button><br/>
40
41<a href="/"  class="back_button"><ArrowBackIcon style={{color:"white"}}/></a>
42    
43  {
44    this.state.page1 ?
45    (
46      <a href="/q2">Next</a>
47    )
48    :
49    (
50      this.state.page2 ?
51      (
52        <a href="/q22">Next</a>
53      ) :
54      (this.state.page3 ?
55      (
56        <a href="/q23">Next</a>
57      )
58      :
59      (
60        <a href="">Next</a>
61      )
62    )
63    )
64  }
65