Created
May 16, 2019 04:43
-
-
Save hliang/40a92cc0b182b107f6bc40c258a60ba5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { connect } form 'react-redux'; | |
const SAVE_WEATHER = "SAVE_WEATHER"; | |
export default function saveWeather(response) { | |
return { | |
type: SAVE_WEATHER, | |
data: response | |
} | |
} | |
export default weatherReducee(state = {}, action) { | |
switch (action.type) { | |
case SAVE_WEATHER: | |
return { | |
...state, action.data | |
} | |
default: | |
state; | |
} | |
} | |
class App extend React.Component { | |
componentDidMount() { | |
const response = axios.get('/weatherApiURL', (data) => { | |
return weatherData | |
}) | |
dispatch(saveWeather(response)) | |
} | |
render() { | |
return ( | |
<div>{this.props.weatherData}</div> | |
) | |
} | |
} | |
function mapStateToProps(state) { | |
return { | |
weatherData: state.weatherData | |
} | |
} | |
export default connect(mapStateToProps)(App) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment