Skip to content

Instantly share code, notes, and snippets.

@hliang
Created May 16, 2019 04:43
Show Gist options
  • Save hliang/40a92cc0b182b107f6bc40c258a60ba5 to your computer and use it in GitHub Desktop.
Save hliang/40a92cc0b182b107f6bc40c258a60ba5 to your computer and use it in GitHub Desktop.
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