Question from the React ⚛️ test

Archived

We want to improve this component so that it displays"Green"by default.

class CSSColors extends React.Component{
  constructor(props){
    super(props);
    this.state={colorCode: ''};
    this.changeColor= this.changeColor.bind(this);
  }
  
  changeColor(evt){
    this.setState({colorCode: evt.target.value});
  }
  
  render(){
    return(
     <div>
        The color code
       <select onChange={this.changeColor}>
         <option value="#ff0000">Red</option>
         <option value="#00ff00">Green</option>
         <option value="#0000ff">Blue</option>
       </select>
        is{this.state.colorCode}
     </div>
    );
  }
}

How to do ?

Author: Victor SabatierStatus: ArchivedQuestion passed 1060 times
1
Community EvaluationsNo one has reviewed this question yet, be the first!