Created
August 11, 2017 23:37
-
-
Save ghoshabhi/8af3b059ae4ecdb333783a7da4c01b26 to your computer and use it in GitHub Desktop.
This file contains 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
export const fetchByPostId = id => { | |
const data = API.getPostById(id); | |
return { | |
type: FETCH_POST_BY_ID, | |
payload: data, | |
} | |
} |
This file contains 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 React, { Component } from 'react'; | |
import { connect, bindActionCreators } from 'react-redux'; | |
import * as actions from '../some/actionCreatorFile.js'; | |
class FooContainer extends Component { | |
componentDidMount() { | |
this.props.fetchByPostId(this.props.match.params.id); | |
} | |
render() { | |
return ( | |
<SomeStateLessComponent post={this.props.postFoo} /> | |
) | |
} | |
} | |
// State => Props | |
mapStateToProps = (state) => { | |
return { | |
postFoo: state.postConatiner.post, | |
} | |
} | |
export default connect(mapStateToProps, { actions })(FooContainer); |
This file contains 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 types (FETCH_POST_BY_ID) | |
const initialState = { | |
post: {}, | |
} | |
const postReducer = (state = initialState, action) => { | |
switch(action.type) { | |
case FETCH_POST_BY_ID: { | |
return { | |
...state, | |
post: action.payload, | |
} | |
} | |
default: | |
return state; | |
} | |
} | |
export default initialState; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment