I need a button color to change onClick multiple times for example from red to blue , blue to green and more but cannot determine how to do

I need a button color to change onClick multiple times for example from red to blue , blue to green and more but cannot determine how to do
0

#1

Index.js

import React from ‘react’;
import { render } from ‘react-dom’;
import Hello from ‘./Hello’;
import MyButton from ‘./MyButton’;

const styles = {
fontFamily: ‘sans-serif’,
textAlign: ‘center’,

};
const bStyle = {
textAlign: ‘center’,
BackgroundColor: ‘red’,
};
let colors = [‘red’, ‘blue’, ‘green’,];

class App extends React.Component {
constructor(props) {
super(props);
this.handleClick = this.handleClick.bind(this);
}
state = {
colorIndex: 0,
}

handleClick(e){
this.setState ({
colorIndex: 1,
})
}

render() {
return (



Start editing to see some magic happen {’\u2728’}






);
}
}

render(, document.getElementById(‘root’));

MyButton.js

import React from ‘react’;
import {
Button,
ButtonToolbar,

} from ‘react-bootstrap’;

export default class MyButton extends React.Component {
render() {
return (

{/* Standard button */}

   <Button
       onClick={this.props.onClick} 
    style={{ backgroundColor: this.props.color }}>
       {this.props.name}
   </Button>

  </ButtonToolbar>

);

}
}


#2

Firstly, welcome to the forums.

While we are primarily here to help people with their Free Code Camp progress, we are open to people on other paths, too. Some of what you are asking is pretty trivial in the Free Code Camp context, so you might find that if you’re not getting the instruction and material you need in your current studies, the FCC curriculum will really help you get started. At a modest guess I’d say investing a 4-5 hours working through the curriculum here will really pay off. You can find the curriculum at https://freecodecamp.org.

With your current questions, we don’t have enough context to know what you already know or don’t know, so it is impossible to guide you without just telling you the answer (which we won’t do).

Happy coding :slight_smile: