I used redux-thunk middleware and I'm receiving the values from props only after the render is executed. How can i get the values of 'Contents' to be set in props before render is called??
UNSAFE_componentWillMount() {
this.getAllArticle();
}
getAllArticle = () => {
this.props.onGetAllArticle(); `
}
render() {
{this.props.contents ? this.props.contents.map((obj, index) => (
<tr key={index}>
<td> {obj.id} </td>
<td> {obj.title}</td>
<td> {obj.context}</td>
</tr>
)) : 'No Data'}}
function mapStateToProps(state) {
return {
contents: state.all
}
}
function mapDispatchToProps(dispatch) {
return {
onGetAllArticle: () =>dispatch(actionCreator.onGetAllArticle())
}
}
export default connect(mapStateToProps, mapDispatchToProps)(All);