I'm trying to get a method to load on page load and I found the best way to do this is by using ComponentDidMount(). I can't seem to get it to fire my method. I know that CompoentDidMount() is working tho because I was able to get logging in it.
Here's my ComponentDidMount():
componentDidMount() {
this.props.getStus()
}
And here's my mapToDispatch and Connect:
const mapDispatchToProps = dispatch => {
return{
getStus: () => dispatch(auth.getStus),
}
}
export default connect(mapStateToProps, mapDispatchToProps)(Profile);
Here's my action code:
export const getStus = () => {
return (dispatch, getState) => {
console.log("In getStus");
let headers = {"Content-Type": "application/json"};
return fetch(`${url}/api/stu/list/`, {headers, body: "", method: "GET"})
.then(res => {
if (res.status < 500) {
return res.json().then(data => {
return {status: res.status, data};
})
} else {
throw res;
}
})
.then(res => {
if (res.status === 200) {
dispatch({type: 'GET_STUS_SUCCESSFUL'});
return res.data;
} else if (res.status === 403 || res.status === 401) {
dispatch({type: "AUTHENTICATION_ERROR", data: res.data});
throw res.data;
}
})
}
}
Any help would be appreciated. Thanks.