pdxmike
1/10/2017 - 6:44 PM

Trying to use ES6 class

Trying to use ES6 class

Warning: Failed prop type: Invalid prop `location` of type `object` supplied to `Weather`, expected `string`.
    in Weather (created by RouterContext)
    in RouterContext (created by Router)
    in Router
import React from 'react'

class WeatherMessage extends React.Component{
  render(){
    let {temp, location} = this.props;
    
    return(
      <div>
        <p>It is {temp} degrees in {location}</p>
      </div>
    )
  }
}

export default WeatherMessage;
import React from 'react'
import WeatherForm from 'WeatherForm'
import WeatherMessage from 'WeatherMessage'

class Weather extends React.Component{
  constructor(props){
    super(props);

    this.state = {
      location: 'Miami',
      temp: 88
    }
  }
  handleSearch = (location) => {
    this.setState({
      location: location,
      temp: 33
    });
  }
  render(){
    let {temp, location} = this.state;

    return(
      <div>
        <h1>Get Weather</h1>
        <WeatherForm onSearch={this.handleSearch}/>
        <WeatherMessage temp={this.temp} location={this.location}/>
      </div>
    );
  }
};

Weather.defaultProps = {
  location: 'Miami',
  temp: 88
}

Weather.propTypes = {
  location: React.PropTypes.string,
  temp: React.PropTypes.number
}

export default Weather;