I have a component which is dependent on redux store. My redux store looks like this something
{
user: {
auth: true,
id: '5a603c58288fc745f8cada9e',
first_name: 'john',
email: 'xyz@abc.com',
company_id: '5a66d8b92cd8e931680778dc',
company_name: 'My Company',
}
}
So basically when i refresh the page, store goes away and it takes sometime to fetch data and set it into store as above
I have a component which requires company_id to fetch data about that company
componentDidMount(props) {
console.log("idddddddd", this.props.company_id)
// this.props.getCompanyData(this.props.company_id);
}
using react-redux i am getting the company_id
CompanySetupPage.propTypes = {
getCompanyData : PropTypes.func.isRequired,
company_id : PropTypes.string.isRequired
}
function mapStateToProps(state) {
return {
company_id : state.user.company_id
}
}
export default connect(mapStateToProps, {getCompanyData})(CompanySetupPage);
this component, componentDidMount is being fired before store receives company_id data. So what i want is i want componentDidMount to be called after this component gets company_id from redux store.