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!
14
Save the state used to display the selected page in a React component.11
Use useCallback to optimize rendering in React17
Write a React component as a function18
Call a function on the first render of a React component27
Write the missing code to render the children of the UserProfile component.34
Write the non-JSX equivalent of the following code:10
Write a React component that displays the sum of two numbers