Skip to content

Instantly share code, notes, and snippets.

@mssngr
Created May 1, 2018 04:17
Show Gist options
  • Save mssngr/02c17647d13a2ac97242ada3b8362a60 to your computer and use it in GitHub Desktop.
Save mssngr/02c17647d13a2ac97242ada3b8362a60 to your computer and use it in GitHub Desktop.
// Component.jsx
componentDidMount () {
const url = `${ ROOT_URL }event/${ this.props.eventId }`
axios.get(url)
.then(response => response.data && this.props.eventFetch(response.data))
.catch(err => console.log(err))
}
const mapState = (state) => {
const { eventName, eventDescription } = state
return { eventName, eventDescription }
}
const mapActions = {
eventFetch: Actions.eventFetch,
}
export default connect(mapState, mapActions)(EventDetails)
// actions.js
export const eventFetch = (data) => ({
type: EVENT_FETCH,
payload: { data },
})
// reducers.js
case EVENT_FETCH: {
const fetchedState = action.payload && action.payload.data
return fetchedState
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment