set meterial icon color change onclick react

Solutions on MaxInterview for set meterial icon color change onclick react by the best coders in the world

showing results for - "set meterial icon color change onclick react"
Rahma
07 Jan 2019
1class Utilitybar extends React.Component {
2  constructor(props) {
3    super(props)
4    this.onButtonClicked = this.onButtonClicked.bind(this)
5    this.state = { currentButton: null }
6  }
7
8  onButtonClicked (id) {
9    this.setState({ currentButton: this.state.currentButton === id ? null : id })
10  }
11
12  render(){
13    return (
14      <div>
15        <IconButton
16          color={this.state.currentButton === 0 ? "primary" : "default" }
17          onClick={() => this.onButtonClicked(0)}>
18          <FaPlayCircle/>
19        </IconButton>
20        <IconButton
21          color={this.state.currentButton === 1 ? "primary" : "default" }
22          onClick={() => this.onButtonClicked(1)}>
23          <FaRegFileAlt/>
24        </IconButton>
25      </div>
26    );
27  }
28}
29