Skip to content

Instantly share code, notes, and snippets.

@cevr
Last active December 19, 2018 17:44
Show Gist options
  • Save cevr/57c236fcaff69ea454d5dbf83ffcb647 to your computer and use it in GitHub Desktop.
Save cevr/57c236fcaff69ea454d5dbf83ffcb647 to your computer and use it in GitHub Desktop.
export function getObjectives() {
return dispatch => {
dispatch(isLoading());
axios
.get('url')
.then(res => {
dispatch(setObjectives(res.data))
dispatch(isNotLoading());
})
.catch(err => {
console.log(err);
});
};
}
class Child extends React.Component {
state = {
columns: ObjectivesTableLabel,
objectives: [],
};
componentDidMount() {
this.props.getObjectives();
}
render() {
let { columns } = this.state;
const { objectives } = this.props;
return (
<div>
....
</div>
);
}
}
const mapStateToProps = state => ({
objectives: state.objectives.objectives,
currentItem: state.dailyPlan.currentItem,
});
const mapDisaptchToProps = {
getObjectives,
};
export default connect(
mapStateToProps,
mapDisaptchToProps,
)(Objectives);
class Parent extends Component {
render() {
const { classes, isLoading } = this.props;
return (
<React.Fragment>
<Grid item xs={9}>
<div className={classes.dailyplan}>
{isLoading ? (
<LoadingSpinner />
) : (
<Switch>
<Route path="/dailyplan/:id/configuration-3/objectives" component={Child} />
</Switch>
)}
</div>
</Grid>
</React.Fragment>
);
}
}
const mapStateToProps = state => ({
dailyPlanList: state.dailyPlan.dailyPlanList,
isLoading: state.indicators.isLoading,
currentItem: state.dailyPlan.currentItem,
optimizationStatus: state.dailyPlan.optimizationStatus,
});
const mapDispatchToProps = {
getItems,
setCurrentItem,
getOptimizationStatus,
setOptimizationStatus,
getObjectives,
};
const StyledDailyPlan = withStyles(styles)(DailyPlan);
export default connect(
mapStateToProps,
mapDispatchToProps,
)(StyledDailyPlan);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment