I am trying to figure out how can i manage/display this component when data is still loading.
I am using react redux for this case.
any suggestion for solving this out?
Although I wrapped this with lazy loading but it seems it is not that much working in this case.
Any suggestion for this.
//Actions.js
export const getContact= () => dispatch => {
dispatch(setResumesLoading());
axios
.get('/api/contacts')
.then(res =>
dispatch({
type: GET_CONTACTS,
payload: res.data
})
).catch (err => dispatch (returnErrors(err.response.data, err.response.status)));
};
//component.js
import React, {Component} from 'react';
import {Grid, Cell, List, ListItem, ListItemContent, Button} from 'react-mdl';
import { connect } from 'react-redux';
import { getContact, deleteContact} from '../../actions/resumeActions';
import PropTypes from 'prop-types';
class Contact extends Component{
static propTypes = {
getContact: PropTypes.func.isRequired,
deleteContact: PropTypes.func.isRequired,
resume: PropTypes.object.isRequired,
isAuthenticated: PropTypes.bool,
auth: PropTypes.object.isRequired
}
componentDidMount() {
this.props.getContact();
}
onDeleteContactClick = (id) => {
this.props.deleteContact(id);
};
render(){
const { contacts } = this.props.resume;
const { user } = this.props.auth;
return(
<div>
{/* {loading ? <Loading /> : <ResultsComponent results={data} />} */}
{contacts.map(({ _id, contact_name, contact_phone, contact_email, contact_skype, contact_image }) => (
<Grid key={_id} timeout={100} classNames="fade">
{ this.props.isAuthenticated && (user.is_admin === true) ?
<Button className="remove-btn"
color="danger"
size="sm"
onClick= {this.onDeleteContactClick.bind(this, _id)}>
×
</Button> : null }
<Cell col={6}>
<div style={{textAlign: 'center'}}>
<h2> {contact_name} </h2>
<img src={contact_image}
alt="avatar"
style={{height: '40%', borderRadius: '50%', width: '50%'}}
img-rounded />
</div>
</Cell>
<Cell col={6} className="contact-right-col text-center">
<h2 >Contact Me</h2>
<hr className="resume-left-contact-section-border" />
<List>
<ListItem>
<ListItemContent className="contact-list-item">
<i className="fa fa-phone-square" aria-hidden="true"/>
{contact_phone}
</ListItemContent>
</ListItem>
</List>
</Cell>
</Grid>
))}
</div>
)
}
}
const mapStateToProps = (state) => ({
resume: state.resume,
isAuthenticated : state.auth.isAuthenticated,
auth: state.auth
});
export default connect(mapStateToProps, {getContact, deleteContact }) (Contact);