// App.js
import React, { Component } from 'react';
class App extends Component {
changeColor() {
this.setState({
backgroundColor: '#afa'
});
}
render() {
return (
<div className="App" style={{ backgroundColor: this.state.backgroundColor }}>
<button onClick={this.changeColor}>Change component background</button>
</div>
);
}
}
export default App;
// index.js
...
ReactDOM.render(
<App />,
document.getElementById('root')
);