import React, {Component} from 'react';
// import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';

class ColorPalette extends Component {
  buildPalette() {
    let roomSelected = this.props.roomSelected;
    const color = this.props.rooms[roomSelected].color && this.props.rooms[roomSelected].color.hex;
    let rectWidth = 100;
    return <rect x="0" y="0" fill={color || 'white'} width={rectWidth} height="50" />
  }

  render() { 
    let rects;
    let rectWidth = 100;
    rects = this.buildPalette();
    return (
      <div>
        <svg width={rectWidth * (rects.length - 1) || rectWidth}>
          <g>
          {rects}
          </g>
        </svg>
      </div>
    )
  }
};

function mapStateToProps({ rooms, roomSelected }) {
  return { rooms, roomSelected };
}

// function mapDispatchToProps(dispatch) {
//   return bindActionCreators({selectRoom}, dispatch);
// }


export default connect(mapStateToProps)(ColorPalette);

import React, {Component} from 'react';
// import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';

class ColorPalette extends Component {
  buildPalette() {
    const roomSelectedName = this.props.roomSelected;
    const room = this.props.rooms[roomSelectedName];
    const color = room && room.color && room.color.hex;
    let rectWidth = 100;
    return <rect x="0" y="0" fill={color || 'white'} width={rectWidth} height="50" />
  }

  render() { 
    return (
      <div>
        <svg width={100}>
          <g>
          {this.buildPalette()}
          </g>
        </svg>
      </div>
    )
  }
};

function mapStateToProps({ rooms, roomSelected }) {
  return { rooms, roomSelected };
}

// function mapDispatchToProps(dispatch) {
//   return bindActionCreators({selectRoom}, dispatch);
// }


export default connect(mapStateToProps)(ColorPalette);

Fix error thrown when loading a room page directly
fix: Fix error thrown when loading a room page directly

When loading a specific page from its url (e.g., 'http://localhost:3000/furniture/den'), an error would be thrown by ColorPalette. Now that doesn't happen.
