<div id='app'></div>
@import url(https://fonts.googleapis.com/css?family=Roboto:100);

h2 {
  font-family: 'Roboto', sans-serif;
  font-weight: 100;
  margin: 10px;
}

button {
	background-color:transparent;
	-moz-border-radius:5px;
	-webkit-border-radius:5px;
	border-radius:5px;
	border:1px solid #bdbdbd;
	display:inline-block;
	cursor:pointer;
	color:#bdbdbd;
	font-family:Arial;
	font-size:16px;
	padding:10px 20px;
  margin: 10px;
	text-decoration:none;
  transition: all 0.4s ease;
}
button:hover {
	color: #76daff;
  border: 1px solid #76daff;
}
button:focus {
  outline: 0;
}

.usercard {
  height: 170px;
  width: 300px;
  border: 1px solid #bdbdbd;
  border-radius: 15px;
}

.circle {
  height: 100px;
  width: 100px;
  border-radius: 50%;
  margin: 10px;
  transition: background-color 1s ease;
}
class User extends React.Component {
  constructor(props){
    super(props);
    
    // Move the currentColor to top-level state
    this.state={
      currentColor: '#f8c483'
    }
  }
  
  // Hook context favColor to this.state.currentColor
  getChildContext() {
    return {
      favColor: this.state.currentColor,
      userName: 'James Ipsum'
    }
  }
  
  // Swap between colors on click
  swapColor () {
    if(this.state.currentColor === '#f8c483'){
      this.setState({
        currentColor: '#76daff'
      })
    } else {
      this.setState({
        currentColor: '#f8c483'
      })
    }
  }
  
  render() {
    return(
      <div>
        <Usercard />
        <button onClick={this.swapColor.bind(this)}>Swap Color</button>
      </div>
    );
  }
}

User.childContextTypes = {
  favColor: React.PropTypes.string,
  userName: React.PropTypes.string
};

class Usercard extends React.Component {
  // Usercard again makes no use of context
  render() {
    return(
      <div className='usercard'>
        <UserIcon />
        <UserInfo />
      </div>
    );
  }
}

class UserInfo extends React.Component {
  render() {
    return(
      <h2>{this.context.userName}</h2>
    );
  }
}

UserInfo.contextTypes = {
  userName: React.PropTypes.string
};

class UserIcon extends React.Component {
  // The context value for favColor now correctly corresponds to the currentColor value in the User component state
  render() {
    return(
      <div 
        className='circle' 
        style={{
          backgroundColor: this.context.favColor
        }}></div>
    );
  }
}

UserIcon.contextTypes = {
  favColor: React.PropTypes.string
};

ReactDOM.render(<User />, document.getElementById('app'));
View Compiled

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://fb.me/react-15.1.0.min.js
  2. https://fb.me/react-dom-15.1.0.min.js